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 {
...