IAPManager 0.2.4

IAPManager 0.2.4

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布上次发布2014年12月

Marcel Ruegenberg维护。



  • 作者
  • Marcel Ruegenberg

对iOS还简单的一个内购界面。

一个简单的不续订(也就是“高级功能”)内购工具包。主要目标是易于使用。因此,没有提供更复杂的部分,如检查收据。

功能

  • 简单设置
  • 检查产品是否被购买的有效一行检查
  • SKProducts以获取价格
  • 恢复购买
  • 使用块进行回调

需求

iOS 5或更高版本,具有ARC和StoreKit框架。

如何使用

  1. 在iTunes Connect中创建您的购买。有关详细信息,请参阅内购编程指南。
  2. 将StoreKit框架添加到您的项目中
  3. 将`IAPManager.h`和`IAPManager.m`添加到您的项目中,或使用Pod`IAPManager
  4. 创建您的IAP用户界面
  5. 使用`[IAPManager sharedIAPManager]`单例的方法
    • 检查App Store是否可用:`[[IAPManager sharedIAPManager] canPurchase]`
    • 获取产品信息
[[IAPManager sharedIAPManager] getProductsForIds:@[@"superpremiumversion"]
                                      completion:^(NSArray *products) {
                                          BOOL hasProducts = [products count] != 0;
                                          if(! hasProducts) {
                                              NSLog(@":(");
                                          }
                                          else {
                                              SKProduct *premium = products[0];

                                              NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];                                                                                                                 [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
                                              [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
                                              [numberFormatter setLocale:premium.priceLocale];
                                              NSString *formattedPrice = [numberFormatter stringFromNumber:premium.price];
                                              NSLog(@"super premium: %@ for %@", premium.localizedTitle, formattedPrice);
                                          }
}];
- To purchase a product:
[[IAPManager sharedIAPManager] purchaseProductForId:@"superpremiumversion"
                                         completion:^(SKPaymentTransaction *transaction) {
                                             [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
                                             UIAlertView *thanks = [[UIAlertView alloc] initWithTitle:@"Thanks!"
                                                                                              message:@"The extra features are now available"
                                                                                             delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                                             [thanks show];
                                         } error:^(NSError *err) {
                                             [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

                                             NSLog(@"An error occured while purchasing: %@", err.localizedDescription);
                                             // show an error alert to the user.
                                         }];
  StoreKit will then ask the user if they want to purchase the product.

联系方式

Travis CI build status

欢迎进行错误报告和pull requests! 通过电子邮件或直接在GitHub上打开问题与我联系。