Revenue Cat (SwiftUI) 的购买问题“收据无效”

gtx*_*eme 8 in-app-purchase ios in-app-billing revenuecat swiftui

我一直在尝试具体测试应用程序内购买(自动续订订阅),并且我总是看到“收据无效”在这方面,一旦购买完成,我想写入true一个名为premium I have的 bool 值首先尝试在应用程序启动时检查用户是否已订阅,如果用户已订阅则执行相同的逻辑(解锁高级版)

这是我的代码

应用程序 didFinishlaunchingWithOptions

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

      // Init other stuff
       Purchases.configure(withAPIKey: Config.REVENUE_CAT_API_KEY)
       checkAllPurchases()
}
Run Code Online (Sandbox Code Playgroud)

检查所有购买()

 func checkAllPurchases(){
        Purchases.shared.purchaserInfo { (purchaseInfo, err) in
            print("Purchase info :", purchaseInfo?.entitlements.all)
            if(err != nil){
                if purchaseInfo?.entitlements["allaccess"]?.isActive == true {
                    UserDefaults.standard.setValue(true, forKey: "premium")
                }
            }
            else{
                self.purchaseError = err?.localizedDescription ?? ""
                //print(err?.localizedDescription)
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

购买()

单击购买按钮时会调用此函数

func purchase (productId : String?){
        guard productId != nil else {
            return
        }
        var skProduct : SKProduct?
        
        Purchases.shared.products([productId!]) { (skProducts) in
            if !skProducts.isEmpty{
                skProduct = skProducts[0]
            
                print("SKProduct:", skProducts[0].productIdentifier)
            Purchases.shared.purchaseProduct(skProduct!) { (transaction, purchaseInfo, error, userCancelled) in
                // If successfull purchase
               
                if (error == nil && !userCancelled){
                    UserDefaults.standard.setValue(true, forKey: "premium")
                }
                else if (error != nil && !userCancelled){
                    self.purchaseError = error?.localizedDescription ?? ""
                    if let err = error as NSError? {
                        print("Error: \(err.userInfo)")
                        print("Message: \(err.localizedDescription)")
                        print("Underlying Error: \(String(describing: err.userInfo[NSUnderlyingErrorKey]))")
                    }
                }
            }
            }
        }
    }

Run Code Online (Sandbox Code Playgroud)

这里有一个未解决的问题,但似乎只有 StoreKit 文件的情况,而不是物理沙盒测试的情况我在这两种情况下都有这个问题,现在我不知道如何测试我的应用内购买

enc*_*ife 3

通常,“收据无效”错误表示某些 iOS / Xcode 配置出现错误。我确认:

  • 您已遵循 StoreKit 测试指南(对模拟器和设备有效): https: //docs.revenuecat.com/docs/apple-app-store#ios-14-only-testing-on-the-simulator
  • 您正在使用最新的 RevenueCat Purchasing SDK
  • 对产品或代码签名进行任何更改后,您已重新上传 StoreKit 证书
  • 您已确认为您的应用正确设置了 Bundle ID 和共享密钥
  • StoreKit 文件中的所有产品均列在 RevenueCat 仪表板中

此外,如果您使用任何其他第三方购买的 SDK,它们可能会干扰验证过程。