I suspect it's got something to do with the subscription-based in-app purchase. Everything works fine in development mode and on TestFlight, even running Ad Hoc. But when it hits the App Store, it crashes every single time.
I've checked crash logs, and the only info I'm getting is that it is a SIGTRAP.
I think it's in this code:
func checkForSubscription {
print("Checking subscription status")
guard let receiptURL = Bundle.main.appStoreReceiptURL else {
return
}
let fileManager = FileManager()
if fileManager.fileExists(atPath: receiptURL.path) {
do {
let receipt = try! Data(contentsOf: receiptURL)
let requestContents = [
"receipt-data": receipt.base64EncodedString(options: []),
"password": "secret generated from iTunes Connect"
]
let requestData = try JSONSerialization.data(withJSONObject: requestContents, options: [])
let storeURL = URL(string: "https://buy.itunes.apple.com/verifyReceipt")
let sandboxURL = URL(string: "https://sandbox.itunes.apple.com/verifyReceipt")
var request = URLRequest(url: storeURL!)
request.httpMethod = "POST"
request.httpBody = requestData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let httpResponse = response as? HTTPURLResponse, let receivedData = data else {
print("No valid http response.")
return
}
switch (httpResponse.statusCode) {
case 200:
do {
let data = try JSONSerialization.jsonObject(with: receivedData, options: .allowFragments)
let json = JSON(data) // SwiftyJSON
let receipts = json["receipt"]["in_app"].array!
let latestReceipts = json["latest_receipt_info"].array!
var allReceipts = receipts + latestReceipts
var expiresTime: Double = 0
for receipt in allReceipts {
let expiration = receipt["expires_date_ms"].doubleValue / 1000
if expiration > expiresTime {
expiresTime = expiration
}
}
let currentTime = NSDate().timeIntervalSince1970
let expired = currentTime > expiresTime
if expired {
subscribed = false
} else {
subscribed = true
}
} catch {
print(error)
}
default:
print("Error code: \(httpResponse.statusCode)")
}
}
task.resume()
} catch {
// May be because there is no history of subscription
print(error)
}
} else {
print("no receipt")
}
}