IAPController 2.0.0

IAPController 2.0.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布时间最后发布时间2016年10月

Mattias Eriksson维护。



  • Mattias Eriksson

应用内购买控制器

安装

pod 'IAPController'

Swift(默认)

pod 'IAPController/Swift'

Objective-C

pod 'IAPController/ObjC'

使用

创建一个名为IAPControllerProductIds.plist的plist文件,其中包含您的应用内购买的标识符

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
  <string>com.thematerik.IAPController.product1</string>
  <string>com.thematerik.IAPController.product2</string>
</array>
</plist>

在您的AppDelegate的didFinishLaunchingWithOptions方法中获取产品

IAPController.sharedInstance.fetchProducts()

使用观察者监听应用内购买事件

  • IAPControllerFetchedNotification:当从商店获取产品时
  • IAPControllerPurchasedNotification:当一个产品被购买时
  • IAPControllerFailedNotification:当交易无法完成时
  • IAPControllerRestoredNotification:当用户恢复其应用内购买时

SKProduct提供了一些有用的辅助方法,例如

if let product = IAPController.sharedInstance.products?.first {
    // Printing the price of the product
    print(product.priceFormatted)
    // Buying the product
    product.buy()
}

通过调用以下方法来恢复购买:

IAPController.sharedInstance.restore()

相同的API调用也适用于Objective-C