Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 117 lines (87 sloc) 2.588 kb
d5a2bcf @millenomi Initial commit.
authored
1 //
2 // ILSimSKProductRequest.m
3 // SimStoreKit
4 //
5 // Created by ∞ on 02/02/10.
6 // Copyright 2010 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "ILSimSKProductsRequest.h"
10 #import "ILSimSKProduct_Private.h"
11 #import "ILSimSKTiers.h"
12
13 @interface ILSimSKProductsRequest ()
14
15 @end
16
17 @interface ILSimSKProductsResponse ()
18 - (id) initWithProducts:(NSArray*) p invalidProductIdentifiers:(NSArray*) i;
19 @end
20
21
22 @implementation ILSimSKProductsRequest
23
24 + (id) allocWithZone:(NSZone*) z;
25 {
26 return [[self class] allocWithZone:z];
27 }
28
29 // Default behavior: none found.
30
31 - (id) initWithProductIdentifiers:(NSSet*) productIdentifiers;
32 {
33 if (self = [super init]) {
34 ids = [productIdentifiers copy];
35 }
36
37 return self;
38 }
39
40 @synthesize delegate;
41
42 - (void) dealloc
43 {
44 [ids release];
45 [super dealloc];
46 }
47
48
49 - (void) start;
50 {
51 NSMutableArray* prods = [NSMutableArray array], * badIDs = [NSMutableArray array];
52
53 for (NSString* ident in ids) {
54 ILSimSKProduct* p = [[self class] simulatedProductForIdentifier:ident];
55 if (p)
56 [prods addObject:p];
57 else
58 [badIDs addObject:ident];
59 }
60
61 ILSimSKProductsResponse* r = [[[ILSimSKProductsResponse alloc] initWithProducts:prods invalidProductIdentifiers:badIDs] autorelease];
62
63 [self.delegate productsRequest:self didReceiveResponse:r];
293cfd9 @millenomi Added test app, fixed typos, added restoring.
authored
64 if (!cancelled && [self.delegate respondsToSelector:@selector(requestDidFinish:)])
d5a2bcf @millenomi Initial commit.
authored
65 [self.delegate requestDidFinish:self];
66 }
67
68 - (void) cancel;
69 {
70 cancelled = YES;
71 }
72
73 + (ILSimSKProduct*) simulatedProductForIdentifier:(NSString*) ident;
74 {
75 NSString* productsFile = [[[NSProcessInfo processInfo] environment] objectForKey:@"ILSimSKProductsPlist"];
76 NSDictionary* d = [NSDictionary dictionaryWithContentsOfFile:productsFile];
77
78 NSDictionary* productData = [d objectForKey:ident];
79 if (!productData)
80 return nil;
81
82 ILSimSKProduct* p = [[ILSimSKProduct new] autorelease];
83 p.productIdentifier = ident;
84 p.localizedTitle = [productData objectForKey:@"Title"];
85 p.localizedDescription = [productData objectForKey:@"Description"];
86
87 NSInteger i = [[productData objectForKey:@"Tier"] unsignedIntegerValue];
88 p.price = ILSimSKPriceAtTierForCurrentStorefront(i);
89 p.priceLocale = ILSimSKLocaleForCurrentStorefront();
90 return p;
91 }
92
93 @end
94
95 @implementation ILSimSKProductsResponse
96
97 - (id) initWithProducts:(NSArray*) p invalidProductIdentifiers:(NSArray*) i;
98 {
99 if (self = [super init]) {
100 products = [p copy];
101 invalidProductIdentifiers = [i copy];
102 }
103
104 return self;
105 }
106
107 @synthesize products, invalidProductIdentifiers;
108
109 - (void) dealloc
110 {
111 [products release];
112 [invalidProductIdentifiers release];
113 [super dealloc];
114 }
115
116 @end
Something went wrong with that request. Please try again.