forked from mineek/MuffinStore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoreKitDownloader.m
More file actions
66 lines (52 loc) · 2.51 KB
/
StoreKitDownloader.m
File metadata and controls
66 lines (52 loc) · 2.51 KB
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
#import "StoreKitDownloader.h"
@interface SKUIItemStateCenter : NSObject
+ (id)defaultCenter;
- (id)_newPurchasesWithItems:(id)items;
- (void)_performPurchases:(id)purchases hasBundlePurchase:(_Bool)purchase withClientContext:(id)context completionBlock:(id /* block */)block;
- (void)_performSoftwarePurchases:(id)purchases withClientContext:(id)context completionBlock:(id /* block */)block;
@end
@interface SKUIItem : NSObject
- (id)initWithLookupDictionary:(id)dictionary;
@end
@interface SKUIItemOffer : NSObject
- (id)initWithLookupDictionary:(id)dictionary;
@end
@interface SKUIClientContext : NSObject
+ (id)defaultContext;
@end
@implementation StoreKitDownloader
+ (instancetype)sharedInstance {
static StoreKitDownloader *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
- (void)downloadAppWithAppId:(long long)appId versionId:(long long)versionId {
NSString* adamId = [NSString stringWithFormat:@"%lld", appId];
NSString* pricingParameters = @"pricingParameter";
NSString* appExtVrsId = [NSString stringWithFormat:@"%lld", versionId];
NSString* installed = @"0";
NSString* offerString = nil;
if (versionId == 0) {
offerString = [NSString stringWithFormat:@"productType=C&price=0&salableAdamId=%@&pricingParameters=%@&clientBuyId=1&installed=%@&trolled=1", adamId, pricingParameters, installed];
} else {
offerString = [NSString stringWithFormat:@"productType=C&price=0&salableAdamId=%@&pricingParameters=%@&appExtVrsId=%@&clientBuyId=1&installed=%@&trolled=1", adamId, pricingParameters, appExtVrsId, installed];
}
NSDictionary* offerDict = @{@"buyParams": offerString};
NSDictionary* itemDict = @{@"_itemOffer": adamId};
SKUIItemOffer* offer = [[SKUIItemOffer alloc] initWithLookupDictionary:offerDict];
SKUIItem* item = [[SKUIItem alloc] initWithLookupDictionary:itemDict];
[item setValue:offer forKey:@"_itemOffer"];
[item setValue:@"iosSoftware" forKey:@"_itemKindString"];
if(versionId != 0) {
[item setValue:@(versionId) forKey:@"_versionIdentifier"];
}
SKUIItemStateCenter* center = [SKUIItemStateCenter defaultCenter];
NSArray* items = @[item];
dispatch_async(dispatch_get_main_queue(), ^{
[center _performPurchases:[center _newPurchasesWithItems:items] hasBundlePurchase:0 withClientContext:[SKUIClientContext defaultContext] completionBlock:^(id arg1){}];
});
}
@end