必不可少的StoreKit伴侣
StoreKit
是苹果的框架,用于实现应用内购买。它相当不错,但有一些粗糙的边缘。
CargoBay
通过以下功能来平滑这些粗糙部分:
本项目是开源库系列的一部分,涉及iOS应用程序基础设施的关键部分。确保查看其姊妹项目:GroundControl、SkyLab、houston和Orbiter。
NSArray *identifiers = @[
@"com.example.myapp.apple",
@"com.example.myapp.pear",
@"com.example.myapp.banana"
];
[[CargoBay sharedManager] productsWithIdentifiers:[NSSet setWithArray:identifiers]
success:^(NSArray *products, NSArray *invalidIdentifiers) {
NSLog(@"Products: %@", products);
NSLog(@"Invalid Identifiers: %@", invalidIdentifiers);
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
AppDelegate.m
- (void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)options {
[[CargoBay sharedManager] setPaymentQueueUpdatedTransactionsBlock:^(SKPaymentQueue *queue, NSArray *transactions) {
NSLog(@"Updated Transactions: %@", transactions);
}];
[[SKPaymentQueue defaultQueue] addTransactionObserver:[CargoBay sharedManager]];
// ...
}
[[CargoBay sharedManager] verifyTransaction:transaction password:nil success:^(NSDictionary *receipt) {
NSLog(@"Receipt: %@", receipt);
} failure:^(NSError *error) {
NSLog(@"Error %d (%@)", [error code], [error localizedDescription]);
}];
Mattt Thompson
CargoBay可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。