/
ILSimSKProductsRequest.m
124 lines (92 loc) · 2.83 KB
/
ILSimSKProductsRequest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//
// ILSimSKProductRequest.m
// SimStoreKit
//
// Created by ∞ on 02/02/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "ILSimStoreKit.h"
#if kILSimAllowSimulatedStoreKit
#import "ILSimSKProductsRequest.h"
#import "ILSimSKProduct_Private.h"
#import "ILSimSKTiers.h"
#import "ILSimSKPaymentQueue.h"
@interface ILSimSKProductsRequest ()
@end
@interface ILSimSKProductsResponse ()
- (id) initWithProducts:(NSArray*) p invalidProductIdentifiers:(NSArray*) i;
@end
@implementation ILSimSKProductsRequest
- (id) initWithProductIdentifiers:(NSSet*) productIdentifiers;
{
if (self = [super init]) {
ids = [productIdentifiers copy];
}
return self;
}
@synthesize delegate;
- (void) dealloc
{
[ids release];
[super dealloc];
}
- (void) start;
{
NSMutableArray* prods = [NSMutableArray array], * badIDs = [NSMutableArray array];
for (NSString* ident in ids) {
ILSimSKProduct* p = [[self class] simulatedProductForIdentifier:ident];
if (p)
[prods addObject:p];
else
[badIDs addObject:ident];
}
ILSimSKProductsResponse* r = [[[ILSimSKProductsResponse alloc] initWithProducts:prods invalidProductIdentifiers:badIDs] autorelease];
[self performSelector:@selector(produceResponse:) withObject:r afterDelay:2.0];
}
- (void) produceResponse:(ILSimSKProductsResponse*) r;
{
[self.delegate productsRequest:self didReceiveResponse:r];
if (!cancelled && [self.delegate respondsToSelector:@selector(requestDidFinish:)])
[self.delegate requestDidFinish:self];
}
- (void) cancel;
{
cancelled = YES;
}
+ (ILSimSKProduct*) simulatedProductForIdentifier:(NSString*) ident;
{
NSString* productsFile = [[[NSProcessInfo processInfo] environment] objectForKey:kILSimSKProductsPlistEnvironmentVariable];
NSDictionary* d = productsFile? [NSDictionary dictionaryWithContentsOfFile:productsFile] : nil;
NSDictionary* productData = [d objectForKey:ident];
if (!productData)
return nil;
ILSimSKProduct* p = [[ILSimSKProduct new] autorelease];
p.productIdentifier = ident;
p.localizedTitle = [productData objectForKey:@"Title"];
p.localizedDescription = [productData objectForKey:@"Description"];
NSInteger i = [[productData objectForKey:@"Tier"] unsignedIntegerValue];
p.price = ILSimSKPriceAtTierForCurrentStorefront(i);
p.priceLocale = ILSimSKLocaleForCurrentStorefront();
NSInteger j = [[productData objectForKey:@"ProductType"] integerValue];
p.simulatedProductType = j;
return p;
}
@end
@implementation ILSimSKProductsResponse
- (id) initWithProducts:(NSArray*) p invalidProductIdentifiers:(NSArray*) i;
{
if (self = [super init]) {
products = [p copy];
invalidProductIdentifiers = [i copy];
}
return self;
}
@synthesize products, invalidProductIdentifiers;
- (void) dealloc
{
[products release];
[invalidProductIdentifiers release];
[super dealloc];
}
@end
#endif // #if kILSimAllowSimulatedStoreKit