Ios 如何确定用户之前是否已订阅-RevenueCat

Ios 如何确定用户之前是否已订阅-RevenueCat,ios,swift,in-app-purchase,auto-renewable,revenuecat,Ios,Swift,In App Purchase,Auto Renewable,Revenuecat,我希望能够确定用户是否曾经订阅过 能够更改“购买”按钮的名称。换句话说,在开始时,按钮会显示,立即试用如果用户当前已订阅,按钮会显示已订阅,但是如果用户过去已订阅,但订阅已过期,我希望在购买按钮上显示续订 目前,除了续订选项外,所有功能都正常工作 override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) Purchases.shared.purchaserInfo { (purc

我希望能够确定用户是否曾经订阅过 能够更改“购买”按钮的名称。换句话说,在开始时,按钮会显示,
立即试用
如果用户当前已订阅,按钮会显示
已订阅
,但是如果用户过去已订阅,但订阅已过期,我希望在购买按钮上显示
续订

目前,除了
续订
选项外,所有功能都正常工作

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
,查看用户购买的所有产品标识符,而不考虑过期日期

或者,如果要特别检查“MyKillerFeatureAuthentication”权限,可以检查
purchaseDateForEntitlement
属性。如果
ActiveRightments
为零,并且有购买日期,则可以假定它以前购买过,然后过期

func配置采购(purchaserInfo:purchaserInfo?){
如果让purchaserInfo=purchaserInfo{
如果purchaserInfo.ActiveRightments.contains(“MyKillerFeatureRightage”){
myButton.setTitle(“已订阅”,用于:。正常)
labelAutoTaxDescription.text=“您目前已订阅。感谢您的支持。”
让dateFormatter=dateFormatter()
dateFormatter.dateStyle=.medium
dateFormatter.timeStyle=.medium
如果let expirationDate=purchaserInfo.expirationDate(forEntitlement:“MyKillerFeatureAuthentication”){
self.labelAutoTaxDetectionPrice.text=“过期日期:\(dateFormatter.string(from:expirationDate))”
}
//这里是我需要检查它是否是返回用户的地方,这样我就可以更改按钮的名称
}否则如果purchaserInfo.purchaseDate(forEntitlement:“MyKillerFeatureAuthentication”)!=nil{
myButton.setTitle(“续订”,用于:。正常)
//其他代码
}
}
}
}

请注意,该授权可能已在另一个平台(Android、web等)上解锁,因此iOS上的按钮可能不会触发还原。

@enc_life-您能否澄清一下您的第二个建议?您正在声明以下内容……如果
ActiveRights
为零,并且有一个购买日期,您可以假定它以前购买过,然后过期。但在您的代码中,我们只检查
purchaseDate
是否为
nil
,而不检查权利是否为nil。如果我没有看到明显的错误,很抱歉。@fs\u tigre我更新了答案以包含完整的代码示例。让我知道这更清楚。