我一直在尝试测试应用内购买(自动可更新订阅)的具体情况,但我总是看到“收据无效”在这方面,一旦购买完成,我想写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()
}
checkAllPurchases()
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)
}
}
}
购买()
单击购买按钮时会调用此方法
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]))")
}
}
}
}
}
}
这里有一个未解决的问题,但似乎只有 StoreKit 文件的情况,而不是物理沙盒测试我对这两种情况都有这个问题,现在我不知道如何测试我的应用内购买