Skip to content

HTTPS clone URL

Subversion checkout URL

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