Corrily SDK
安装
Swift 包管理器
- 打开您的 Xcode 项目设置
- 转到项目级别(即不针对目标级别)
- 打开标签 包依赖
- 按 +
- 在右上角的搜索字段中粘贴
https://github.com/corrily/ios-sdk.git
(或相应的 SSH URL) - 选择所需的依赖规则,您想要添加 SDK 的项目和按 添加包 按钮
- 选择
CorrilySDK
,您想要添加 SDK 的目标,并按 添加包 按钮
Cocoapods
示例
pod 'CorrilySDK', '~> 1.0'
使用方法
导入 SDK 模块:import CorrilySDK
所有公共方法都有文档说明,请参见它们的 apidoc 了解详情。
SDK 启动
在应用启动时调用 SDK 的 start()
方法,例如
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
CorrilySDK.start(apiKey: "your_API_key")
return true
}
请求产品
CorrilySDK.requestPaywall(userID: nil, country: .UnitedStates, isDev: true) {
guard let response = $0 else {
print("error requesting paywall: \($1)")
return
}
// process response.monthlyProducts and response.yearlyProducts
}
发送充电请求
这应该在 SKPaymentTransactionObserver
的 updatedTransactions
方法中完成。无论事务状态如何,都调用该方法,例如
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
transactions.forEach {
// here `product` is StoreKit product, probably the one that's being purchased at the moment
// `corrilyProduct` is the corresponding Corrily product
CorrilySDK.requestCharge(
transaction: $0,
product: product,
paywallProduct: corrilyProduct,
userID: nil,
country: .UnitedStates
)
queue.finishTransaction($0)
}
}