Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 125 lines (92 sloc) 2.895 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
8ae8cbe @millenomi Backport of closed source changes from Mover Store:
authored
9 #import "ILSimStoreKit.h"
10 #if kILSimAllowSimulatedStoreKit
11
12
d5a2bcf @millenomi Initial commit.
authored
13 #import "ILSimSKProductsRequest.h"
14 #import "ILSimSKProduct_Private.h"
15 #import "ILSimSKTiers.h"
5166f35 @millenomi Tons of fixes:
authored
16 #import "ILSimSKPaymentQueue.h"
d5a2bcf @millenomi Initial commit.
authored
17
18 @interface ILSimSKProductsRequest ()
19
20 @end
21
22 @interface ILSimSKProductsResponse ()
23 - (id) initWithProducts:(NSArray*) p invalidProductIdentifiers:(NSArray*) i;
24 @end
25
26
27 @implementation ILSimSKProductsRequest
28
29 - (id) initWithProductIdentifiers:(NSSet*) productIdentifiers;
30 {
31 if (self = [super init]) {
32 ids = [productIdentifiers copy];
33 }
34
35 return self;
36 }
37
38 @synthesize delegate;
39
40 - (void) dealloc
41 {
42 [ids release];
43 [super dealloc];
44 }
45
46
47 - (void) start;
48 {
49 NSMutableArray* prods = [NSMutableArray array], * badIDs = [NSMutableArray array];
50
51 for (NSString* ident in ids) {
52 ILSimSKProduct* p = [[self class] simulatedProductForIdentifier:ident];
53 if (p)
54 [prods addObject:p];
55 else
56 [badIDs addObject:ident];
57 }
58
59 ILSimSKProductsResponse* r = [[[ILSimSKProductsResponse alloc] initWithProducts:prods invalidProductIdentifiers:badIDs] autorelease];
60
5166f35 @millenomi Tons of fixes:
authored
61 [self performSelector:@selector(produceResponse:) withObject:r afterDelay:2.0];
62 }
63
64 - (void) produceResponse:(ILSimSKProductsResponse*) r;
65 {
d5a2bcf @millenomi Initial commit.
authored
66 [self.delegate productsRequest:self didReceiveResponse:r];
293cfd9 @millenomi Added test app, fixed typos, added restoring.
authored
67 if (!cancelled && [self.delegate respondsToSelector:@selector(requestDidFinish:)])
d5a2bcf @millenomi Initial commit.
authored
68 [self.delegate requestDidFinish:self];
69 }
70
71 - (void) cancel;
72 {
73 cancelled = YES;
74 }
75
76 + (ILSimSKProduct*) simulatedProductForIdentifier:(NSString*) ident;
77 {
5166f35 @millenomi Tons of fixes:
authored
78 NSString* productsFile = [[[NSProcessInfo processInfo] environment] objectForKey:kILSimSKProductsPlistEnvironmentVariable];
6cbedf9 @millenomi MANY bugfixes.
authored
79 NSDictionary* d = productsFile? [NSDictionary dictionaryWithContentsOfFile:productsFile] : nil;
d5a2bcf @millenomi Initial commit.
authored
80
81 NSDictionary* productData = [d objectForKey:ident];
82 if (!productData)
83 return nil;
84
85 ILSimSKProduct* p = [[ILSimSKProduct new] autorelease];
86 p.productIdentifier = ident;
87 p.localizedTitle = [productData objectForKey:@"Title"];
88 p.localizedDescription = [productData objectForKey:@"Description"];
89
90 NSInteger i = [[productData objectForKey:@"Tier"] unsignedIntegerValue];
91 p.price = ILSimSKPriceAtTierForCurrentStorefront(i);
92 p.priceLocale = ILSimSKLocaleForCurrentStorefront();
6cbedf9 @millenomi MANY bugfixes.
authored
93
94 NSInteger j = [[productData objectForKey:@"ProductType"] integerValue];
95 p.simulatedProductType = j;
d5a2bcf @millenomi Initial commit.
authored
96 return p;
97 }
98
99 @end
100
101 @implementation ILSimSKProductsResponse
102
103 - (id) initWithProducts:(NSArray*) p invalidProductIdentifiers:(NSArray*) i;
104 {
105 if (self = [super init]) {
106 products = [p copy];
107 invalidProductIdentifiers = [i copy];
108 }
109
110 return self;
111 }
112
113 @synthesize products, invalidProductIdentifiers;
114
115 - (void) dealloc
116 {
117 [products release];
118 [invalidProductIdentifiers release];
119 [super dealloc];
120 }
121
122 @end
8ae8cbe @millenomi Backport of closed source changes from Mover Store:
authored
123
124 #endif // #if kILSimAllowSimulatedStoreKit
Something went wrong with that request. Please try again.