swift - InAppPurchase : Download hosted content from AppDelegate

标签 swift swift3 in-app-purchase iap-hosted-content

我正在尝试使用 Apple 服务器中的托管内容实现应用内购买。 我正在使用 SwiftyStoreKit 框架。

通常,根据其他教程,我们需要在以下位置实现下载调用: func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions 交易: [SKPaymentTransaction]) {

所以我在这个函数中实现了以下代码:

let downloads = transaction.downloads
SKPaymentQueue.defaultQueue().startDownloads(downloads)

它正在运行,现在我正在 AppDelegate 中尝试检查先前交易的状态是否为“已购买”但不是“已完成”。这意味着用户已购买该产品,但下载出现问题。

这是我的代码。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
    completeIAPTransactions()
    return true
}

func completeIAPTransactions() {
    SwiftyStoreKit.completeTransactions(atomically: false) { products in
        for product in products {
            if product.transaction.transactionState == .purchased || product.transaction.transactionState == .restored {
                if product.needsFinishTransaction {
                    // Deliver content from server, then:


                    let downloads = transaction.downloads
                    SKPaymentQueue.defaultQueue().startDownloads(downloads)

                    SwiftyStoreKit.finishTransaction(product.transaction)
                }
                print("purchased: \(product.productId)")
            }
        }
    }
}

检查正常,但下载有问题:

Value of type PaymentTransaction has no member downloads.

问题是:当我不在 paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction])

中时,我如何正确启动内容下载

我们将不胜感激。

最佳答案

如果有人偶然发现这个问题,您需要从存储库下载 master 分支,而不是依赖 cocoapods。

pod 'SwiftyStoreKit', :git => "https://github.com/bizz84/SwiftyStoreKit.git"

错误的原因是由于某种原因,在运行 pod install 时并非所有文件都被复制。可能是您的计算机上某处存在缓存版本。

关于swift - InAppPurchase : Download hosted content from AppDelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41346978/

相关文章:

ios - prepareForSegue 目标 TableViewController

ios - 像 Instagram 登录一样更改渐变背景

iOS Swift 3 捆绑通知

ios - 如何删除数组中的项目?

ios - 在 iOS 订阅中,每天/每小时/等调用 verifyReceipt 的频率是否有限制?

android - Google Play 结算安全建议是否仅用于防止盗版?

android billing inApp/subscription 无法找到显式 Activity ProxyBillingActivity

ios - 删除多余的单元格/行空格,而不会在 UITableView 上显示数据

swift - 自定义单元格中的标签和 MPMediaItems

swift - 使用闭包语法在 swift 中声明函数