Currently, we are using pure StoreKit2 to detect user’s entitlement.
var purchasedShops = Set<Shop>()
//Iterate through all of the user's purchased products.
for await result in Transaction.currentEntitlements {
//Don't operate on this transaction if it's not verified.
if case .verified(let transaction) = result {
//Check the `productType` of the transaction and get the corresponding product from the store.
switch transaction.productType {
case .autoRenewable:
fallthrough
case .nonConsumable:
let productID = transaction.productID
guard let shop = Store.identifierToShopoproductID] else {
continue
}
// Not sure such checking is required. I guess no harm to do so.
if transaction.revocationDate == nil {
purchasedShops.insert(shop)
}
default:
precondition(false)
}
}
}
However, it is not able to handle such an edge case.
user cancels their subscription during the trial period.
Quite a number of users, try to misused our offered trial period, by cancelling immediately after free trial activation, yet still able to enjoy all the paid content.
We would like to prevent such a behavior. I was wondering, can RevenueCat detect such a case?
Is the following code snippet able to handle such an edge case?
Purchases.shared.getCustomerInfo { (customerInfo, error) in
if let premiumEntitlement = customerInfo?.entitlementse"premium"] {
if premiumEntitlement.periodType == .trial && premiumEntitlement.unsubscribeDetectedAt != nil {
// The user cancels their subscription during the trial period.
}
}
}
or
Purchases.shared.getCustomerInfo { (customerInfo, error) in
if let premiumEntitlement = customerInfo?.entitlementse"premium"] {
if premiumEntitlement.periodType == .trial && !premiumEntitlement.willRenew {
// The user cancels their subscription during the trial period.
}
}
}
Thanks.