iOS: How to detect if a user is subscribed to an auto-renewable subscription

I know everyone was very concerned about me and how I was doing on this – fear not, solved my problem. Main problem was that I tried Apple’s example code from the documentation, but it wasn’t working so I gave up on it. Then I came back to it and implemented it with Alamofire and it works great. Here’s the code solution:

Swift 3:

let receiptURL = Bundle.main.appStoreReceiptURL
let receipt = NSData(contentsOf: receiptURL!)
let requestContents: [String: Any] = [
    "receipt-data": receipt!.base64EncodedString(options: []),
    "password": "your iTunes Connect shared secret"
]

let appleServer = receiptURL?.lastPathComponent == "sandboxReceipt" ? "sandbox" : "buy"

let stringURL = "https://\(appleServer).itunes.apple.com/verifyReceipt"

print("Loading user receipt: \(stringURL)...")

Alamofire.request(stringURL, method: .post, parameters: requestContents, encoding: JSONEncoding.default)
    .responseJSON { response in
        if let value = response.result.value as? NSDictionary {
            print(value)
        } else {
            print("Receiving receipt from App Store failed: \(response.result)")
        }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)