应用内购买控制器
pod 'IAPController'
pod 'IAPController/Swift'
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