iOS IAP 测试,提示你物品已经买过了

发布时间:2019-06-27 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了iOS IAP 测试,提示你物品已经买过了脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

如果在开发iOS内购的时候,你一定会遇到购买Consumable类物品的需求,比如购买游戏币就是一个很经典的使用场景。最近在测试购买这种消耗品的时候,发现遇到了一个非常奇怪的问题,当你重复购买游戏币的时候,系统提示

This In-App Purchase has already been bought. IT will be reStored for free.

该物品已经购买过了,直接恢复即可。

当你在完成一笔交易的时候,调用StoreKit.SKPaymentQueuefinishTransaction就可以将这个交易标记为已购买,之后应该会没有障碍的继续购买Consumable类的商品。

那么现在这是什么情况的?让人非常费解。
幸好发现了这个和我遇到一样问题的开发者This In-App Purchase Has Aready Been Bought

他也提到,

Apple has designed the payment queue in such a way as to enable apps to fulfill a purchase before completing - with finishTransaction being the indication that fulfillment is complete. In the case that a failure occurs during fulfillment, the app can recover when SKPaymentQueue calls the app’s observer again.

This is all good and fine - except many develoPErs have encountered a situation where this PRocess breaks down. Their SKPaymentTransactionObserver is never called again, and the user is presented with the dreaded “already bought” diaLOG and no apparent way to fix the problem.

SKPaymentTransactionObserver一直没有被调用,并且显示已经购买对话框。

A library (in my case Firebase Analytics) is adding its own SKPaymentTransactionObserver before your app adds its own observer. As a result, SKPaymentQueue is calling that observer First, and by the time your observer is added, as far as the payment queue is concerned it has already delivered the notification and there’s nothing left to do.

他帮我找到了原因——第三方软件(和我一样就是Firebase的问题)。

SKPaymentTransactionObserver没有被调用,其实是因为已经有一个了Observer存在了。

解决方案也比较简单,就是在初始化第三方软件之前,来添加我们的Queue。

因为我在工程里引用了第三方的支付库jinSasaki/InAppPurchase所以下面就用这个为例,简单的写一下解决方案。

class AppDelegate: UIResponder, UIApplicationDelegate {
    // 初始化InAppPurchase
    let iap = InAppPurchase.default
    
    func application(_ application: UIApplication, diDFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // 首先在这边加入Transaction Observer
        iap.addTransactionObserver()
    
        // 然后再开启Firebase的设置
        FirebaseApp.configure()
        return true
    }
}

然后就大功告成了。

脚本宝典总结

以上是脚本宝典为你收集整理的iOS IAP 测试,提示你物品已经买过了全部内容,希望文章能够帮你解决iOS IAP 测试,提示你物品已经买过了所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。