Skip to content

Commit

Permalink
add ask about iAP status after subscription period gone
Browse files Browse the repository at this point in the history
  • Loading branch information
w-i-n-s committed Jun 3, 2021
1 parent 258c96b commit da8f237
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions NthKey/Model/SubscriptionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,6 @@ final class SubscriptionManager: NSObject, ObservableObject {
hasSubscription = Date() < date
}

static private func expirationDateFromResponse(jsonResponse: NSDictionary) -> NSDate? {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss VV"

guard let receiptInfo: NSArray = jsonResponse["latest_receipt_info"] as? NSArray,
let lastReceipt = receiptInfo.lastObject as? NSDictionary,
let dateString = lastReceipt["expires_date"] as? String,
let expirationDate = formatter.date(from: dateString) as NSDate? else { return nil }

return expirationDate
}

/// Allow to have raw estimation of subscription vithout validation
private func checkExpirationDateFromPayment(_ payment: SKPayment) {
let productId = payment.productIdentifier
Expand Down Expand Up @@ -117,6 +105,13 @@ extension SubscriptionManager: SKProductsRequestDelegate {

products = response.products
state = .receivedProducts

// Here we try to ask if iAP still purchased, because we didn't validate receipt, yet.
guard let date = UserDefaults.subscriptionDate,
Date() > date,
products.count == 1,
let unique = products.first else { return }
purchase(product: unique)
}
}

Expand Down

0 comments on commit da8f237

Please sign in to comment.