我希望能够确定用户是否曾经订阅过能够更改购买按钮的名称。换句话说,在开始按钮时,Try It Now
如果当前订阅了用户,则按钮会说Subscribed
,但是如果用户曾经订阅,但是订阅已过期,我想在购买按钮上显示Renew
。
当前所有工作都起作用,除了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
}
}
检查用户是否在之前订阅之前是什么?
您可以检查RCPurchaserInfo
对象上的allPurchasedProductIdentifiers NSSet<NSString *>
,以查看用户购买的所有产品标识符,而不管有效期如何。
另外,如果要检查" mykillerFeatureEntement" prestrement ,则可以检查purchaseDateForEntitlement
属性。如果activeEntitlements
是零,并且有一个购买日期,则可以假设它是先前购买的,然后到期。
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
}
}
}
}
请注意,该权利本可以在另一个平台上解锁(Android,Web等(,因此iOS上的按钮实际上可能不会触发还原。