PurchaseHelper
内购助手和 UI 元素
使用方法
集成
CocoaPods
要使用 CocoaPods 使用 PurchaseHelper,请将以下行添加到您的 Podfile
pod 'PurchaseHelper'
Carthage
要使用 Carthage 使用 PurchaseHelper,请将以下行添加到您的 Cartfile
github "paulyhedral/PurchaseHelper"
助手
一次性创建助手,并在某处保持对其的强引用。
NSSet<NSString*>* productIds = [NSSet setWithObjects:@"product1", @"product2", @"product3", nil];
PurchaseHelper* helper = [[PurchaseHelper alloc] initWithProductIdentifiers:productIds keychainAccount:@"MyIAPs"];
购买产品
[helper buyProduct:@"product2"];
检查是否已购买产品
if([helper productPurchased:@"product3"]) {
// show some feature
}
else {
// encourage the user to buy this feature
}
恢复完成的交易
[helper restoreCompletedTransactions];
UI
创建视图控制器,向其提供一个对助手的引用。自定义其外观,然后显示。
PurchasesViewController* vc = [PurchasesViewController new];
vc.purchaseHelper = helper;
vc.titleFont = appTitleFont;
vc.buttonFont = appButtonFont;
...
[self presentViewController:purchasesVC animated:YES completion:nil];
如果您的应用需要知道购买何时完成,设置一个通知观察者
[[NSNotificationCenter defaultCenter] addObserverForName:ProductPurchasedNotification object:nil queue:nil usingBlock:^(NSNotification* note){
NSString* productId = note.userInfo[ProductPurchasedNotificationProductIdentifierKey];
// do something with the notification
}];
测试模式
在测试应用内购买功能时,将助手置于测试模式。
helper.testMode = YES;
版权
版权所有 © 2016-8 Pilgrimage Software
许可
有关详细信息,请参阅LICENSE。