Hi!
I'm trying to implement a two week free trial for my existing paid ipad app. Following the guidance from the wwdc2022/10007, I'm using AppTransaction.shared
and checking the result. I'm getting a verified result, but the appTransaction.originalPurchaseDate
is always the same date - 2013-08-01 07:00:00 +0000 / 397033200, even the particular sandbox account user never had a purchase.
This makes testing the logical branch of "has this user never purchased this app before" if the app store is always telling us that it's been purchased. (I've been using new sandbox account, so there should be no history)
Here's some code that includes hacking around always getting that original purchase date. We're in the final stretches, and wanting to test things that will be closer to actual store behavior (and I'm thinking that always returning a purchased date for an unpurchased app wouldn't be happening)
Am I just holding things wrong? Sandbox bug/limitatiin I just have to live with?
thanks! ++md
class MJAppStore: NSObject {
@objc static let shared = MJAppStore()
@objc func verifyAppStoreStatus(_ completion: @escaping (MJAppStoreStatus, Error?) -> Void) {
Task {
do {
let status = try await doVerificationThing()
completion(status, nil)
} catch {
completion(.error, error)
}
}
}
func doVerificationThing() async throws -> MJAppStoreStatus {
do {
let result = try await AppTransaction.shared
print("TRIAL: survived AppTransaction.shared")
switch result {
case .unverified(_, _):
print("TRIAL: app transaction UNVERIFIED")
return .free
case .verified(_):
let appTransaction = try result.payloadValue
// hack around the app store sandbox accounts saying we're purchased even though
// we're not really. 2013-08-01 07:00:00 +0000
print("TRIAL: app transaction VERIFIED \(appTransaction.originalPurchaseDate.timeIntervalSinceReferenceDate) -> \(appTransaction.originalPurchaseDate)")
if appTransaction.originalPurchaseDate.timeIntervalSinceReferenceDate == 397033200 {
return .free
} else {
return .purchased
}
}
} catch {
...
Hello! Use originalAppVersion
instead, as mentioned in What's new with in-app purchase | WWDC22:
Customers that purchased my app should be granted the services they paid for. For this, I'll use the original app version property. This property lets me know the app version in which the customer had downloaded my app for the very first time.
Also see Supporting business model changes by using the app transaction:
In version 2, the developer wants to continue to provide the premium features to customers who purchased version 1. To do so, the app performs the following steps:
- The app’s code includes a constant that indicates the version the business model changed; that constant is "2" in this example.
- The app compares the originalAppVersion value with the constant. If the customer purchased the app before the business model changed, the app determines that they’re entitled to the premium features.
- The app also checks the currentEntitlements sequence and delivers any in-app purchases the customers may have made.