[英]How to determine if a user has been subscribed before - RevenueCat
I would like to be able to determine if a user has ever been subscribed to be able to change the name of the purchase button.我希望能够确定用户是否曾经订阅能够更改购买按钮的名称。 In other words, at start the button will say, Try It Now
if the user is currently subscribed the button will say Subscribed
but if the user used to be subscribed but the subscription has been expired I want to display Renew
on the purchase button.换句话说,在开始时,按钮会说,如果用户当前已订阅,则Try It Now
按钮将显示已Subscribed
但如果用户曾经订阅过但订阅已过期,我想在购买按钮上显示Renew
。
Currently everything works except for the Renew
option.目前,除“ Renew
选项外,一切正常。
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
Purchases.shared.purchaserInfo { (purchaserInfo, error) in
self.configurePurchases(purchaserInfo: purchaserInfo)
}
}
func configurePurchases(purchaserInfo: PurchaserInfo?) {
if let purchaserInfo = purchaserInfo {
if purchaserInfo.activeEntitlements.contains("myKillerFeatureEntitlement") {
myButton.setTitle("Subscribed",for: .normal)
labelAutoTaxDescription.text = "You are currently subscribed. Thank you for your support."
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .medium
if let expirationDate = purchaserInfo.expirationDate(forEntitlement: "myKillerFeatureEntitlement") {
self.labelAutoTaxDetectionPrice.text = "Expiration Date: \(dateFormatter.string(from: expirationDate))"
}
}
}
// Here is where I need check if it's a returning user so I can change the name of the button
if isReturningUser{
myButton.setTitle("Renew",for: .normal)
// other code
}
}
What would be the best way to check if a user has been subscribed before?检查用户之前是否订阅过的最佳方法是什么?
You can check the allPurchasedProductIdentifiers NSSet<NSString *>
on the RCPurchaserInfo
object to see all the product identifiers the user has purchased regardless of expiration date.您可以检查RCPurchaserInfo
对象上的allPurchasedProductIdentifiers NSSet<NSString *>
以查看用户购买的所有产品标识符,而不考虑到期日期。
Alternatively, if you want to check for the "myKillerFeatureEntitlement" entitlement specifically, you can check the purchaseDateForEntitlement
property.或者,如果您想专门检查“myKillerFeatureEntitlement”权利,您可以检查purchaseDateForEntitlement
属性。 If the activeEntitlements
is nil and there is a purchase date you can assume it was previously purchased then expired.如果activeEntitlements
为 nil 并且有一个购买日期,您可以假设它之前已购买然后已过期。
func configurePurchases(purchaserInfo: PurchaserInfo?) {
if let purchaserInfo = purchaserInfo {
if purchaserInfo.activeEntitlements.contains("myKillerFeatureEntitlement") {
myButton.setTitle("Subscribed",for: .normal)
labelAutoTaxDescription.text = "You are currently subscribed. Thank you for your support."
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .medium
if let expirationDate = purchaserInfo.expirationDate(forEntitlement: "myKillerFeatureEntitlement") {
self.labelAutoTaxDetectionPrice.text = "Expiration Date: \(dateFormatter.string(from: expirationDate))"
}
// Here is where I need check if it's a returning user so I can change the name of the button
} else if purchaserInfo.purchaseDate(forEntitlement: "myKillerFeatureEntitlement") != nil {
myButton.setTitle("Renew",for: .normal)
// other code
}
}
}
}
Note that the entitlement could have been unlocked on another platform (Android, web, etc.) so the button on iOS may not actually be triggering a restore.请注意,该权利可能已在其他平台(Android、Web 等)上解锁,因此 iOS 上的按钮实际上可能不会触发恢复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.