Code Samples

Implementing and handling mobile subscriptions can be tiresome. Take a look at the code samples below to see some useful subscription implementation cases. Let us know if you have any questions!

A customer already used the free trial offer.

You can check if this is the case and provide him with payment options, excluding the free-trial.

Swift
Objective-C
Swift
Qonversion.checkUser({ result in
guard let trialSubscription = result.allProducts
.first(where: { $0.state == .trial }) else { return }
switch trialSubscription.status {
case .active:
print("Trial still active")
case .cancelled:
print("Trial was cancelled")
default: break
}
}) { _ in
}
Objective-C
[Qonversion checkUser:^(QonversionCheckResult * _Nonnull result) {
[result.allProducts enumerateObjectsUsingBlock:^(RenewalProductDetails * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.state == RenewalProductStateTrial) {
switch (obj.status) {
case RenewalProductStatusActive:
NSLog(@"Trial still active");
break;
case RenewalProductStatusCancelled:
NSLog(@"Trial was cancelled");
break;
default:
break;
}
}
}];
} failure:^(NSError *error) {
}];