这是一个生产错误,由于 customerInfo.activeSubscriptions 返回了之前订阅的所有产品标识符,因此之前订阅过的用户仍然可以访问所有 Pro 功能
返回了所有 customerInfo.activeSubscriptions
,之前订阅过的用户仍然可以访问所有 Pro 功能 productIdentifiers
。
也 customerInfo.entitlements
总是返回值。
我已经添加了
print("ENTITLEMENTS \(customerInfo.entitlements)")
print("ACTIVE SUBS \(customerInfo.activeSubscriptions)")
这将返回
权利 [\'pro\':
我曾尝试使用
customerInfo.entitlements.active
但我得到了相同的结果。
我也尝试过删除缓存信息
Purchases.shared.invalidateCustomerInfoCache()
另外,打开 Debug > StoreKit 时,不会显示交易。
这是验证订阅状态的代码。
func verifyIAPReceipt() {
Purchases.shared.invalidateCustomerInfoCache()
Purchases.shared.getCustomerInfo { (customerInfo, error) in
if error == nil {
if let customerInfo = customerInfo {
if customerInfo.entitlements.active.isEmpty {
print("ENTITLEMENTS IS EMPTY") <-- This is not executed
self.unsubscribe()
} else {
print("ENTITLEMENTS IS NOT EMPTY") <-- Executed
print("ENTITLEMENTS \(customerInfo.entitlements)")
print("ACTIVE SUBS \(customerInfo.activeSubscriptions)")
if customerInfo.activeSubscriptions.isEmpty == false {
print("Active Subscriptions is NOT empty") <-- Executed
for s in customerInfo.activeSubscriptions {
if s == "com.app.come.promonthly" || s == "com.app.com.proyearly" {
subscribe() <-- Executed Unlocks features
}
}
} else if customerInfo.activeSubscriptions.isEmpty == true {
print("Active Subscriptions are empty")
self.unsubscribe()
} else {
print("Active Subscription and profile is subscribed")
}
}
}
} else {
print("ERROR GETTING CUSTOMER INFO TO VERIFY RECEIPTS")
}
}
}
使用时 fetchPolicy: .fetchCurrent
返回有效订阅
Purchases.shared.getCustomerInfo(fetchPolicy: .fetchCurrent, completion: { (customerInfo, error) in
if error != nil {
print("FETCH POLICY ERROR:\(error)")
}
if customerInfo != nil {
print("FETCH POLICY ACTIVE SUBSCRIPTIONS:\(customerInfo!.activeSubscriptions)")
print("FETCH POLICY ACTIVE ENTITLEMENTS:\(customerInfo!.entitlements)")
print("FETCH POLICY ACTIVE ALL PURCHASED PRODUCT ID'S:\(customerInfo!.allPurchasedProductIdentifiers)")
}
})
输出
获取策略有效权利:[\'pro\':
获取政策有效权利:
自我.主动=[:],自我.验证=验证结果.未请求>
获取策略激活所有已购买的产品 ID:[\'com.appname.com.promonthly\', \'com.appname.com.proyearly\']
这是订阅代码
func subscribe() {
print("Subscribe")
//Revenue Cat
if let packages = offering?.availablePackages {
for p in packages {
if p.storeProduct.productIdentifier == selectedproductbundle {
Purchases.shared.purchase(package: p) { (transaction, customerInfo, error, userCancelled) in
print("PURCHASE")
if userCancelled {
print("User cancelled purchase")
return
}
if let err = error {
if let error = error as? RevenueCat.ErrorCode {
print(error.errorCode)
print("ERROR: \(error.errorUserInfo)")
switch error {
case .purchaseNotAllowedError:
errorDescription = "Purchases not allowed on this device."
showError.toggle()
case .purchaseInvalidError:
errorDescription = "Purchase invalid, check payment source."
default: break
}
}
} else if customerInfo?.activeSubscriptions.isEmpty == false {
print("Unlocked Pro ")
// Update profile
print("Customer INFO: \(customerInfo!)")
print("Entitlements: \(customerInfo!.entitlements.all)")
if customerInfo != nil {
for s in customerInfo!.activeSubscriptions {
if s == "com.appname.com.promonthly" || s == "com.appname.com.proyearly" {
subscribeToPro()
}
}
}
} else {
print("PURCHASE WITH: \(String(describing: transaction?.productIdentifier)) && \(String(describing: customerInfo?.activeSubscriptions.count))")
}
}
}
}
}
}
我已经通过模拟器和设备进行了测试。
RevenueCat-customerInfo.activeSubscriptions 始终返回值
下载声明:
本站所有软件和资料均为软件作者提供或网友推荐发布而来,仅供学习和研究使用,不得用于任何商业用途。如本站不慎侵犯你的版权请联系我,我将及时处理,并撤下相关内容!