-3

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")
    }

}
swiftyboi
  • 2,965
  • 4
  • 25
  • 52
  • 1
    What line is crashing? — Also, you do know, don't you, that any time you put an exclamation mark, that _means_ "crash me"? I see at least four of them. That certainly cannot be described as "doing this right". – matt Feb 20 '17 at 21:46
  • 2
    Please provide the full symbolicated crash report – Kerni Feb 20 '17 at 21:46
  • "it crashes every single time." That can't be correct as how did it pass Apple App Store review if it crashes every time? And why not connect a phone to Xcode and get the crash log – Gruntcakes Feb 20 '17 at 21:50
  • 1
    But you need to _symbolicate_ the crash log. – matt Feb 20 '17 at 22:03
  • @piepants It was rejected by Apple several times for this exact reason. Now it's been approved. As to why it was approved, your guess is as good as mine. – swiftyboi Feb 20 '17 at 22:03
  • 2
    So you managed to fool the Apple folks into accepting an app that you knew was crashing, and now you're complaining that the app is crashing?! – matt Feb 20 '17 at 22:05
  • @matt First off, I am not complaining - I am looking for help. So please don't comment unless you are offering it. Second, I did not "fool" Apple into anything. I have filed several support requests regarding the issue and they have not given me any help. My only way of troubleshooting an app that only crashes on the App Store is to put my patches on to the App Store and see if they worked. – swiftyboi Feb 20 '17 at 22:09
  • 1
    I'm commenting, not answering. I _can't_ answer, because you still have not supplied a symbolicated crash log. If you _want_ help, that is what you must supply. All you have supplied is a bogus "the only info I'm getting is that it is a SIGTRAP" (you have _lots_ more info, namely the crash log) and some code that we have no reason to think has anything to do with the crash (but which, as I've already pointed out, is crash-prone code). So yes, I'm using the comments to critique the question — that's what the comments are for. – matt Feb 20 '17 at 22:16

2 Answers2

1

You can integrate Crashlytics in your app, next time if app will crash at app store , you will get class name and line number on your email where your app has crashed.

Amit Singh
  • 172
  • 1
  • 12
1

You can find the line of the crash by symbolicating your crash report.

When you do that you'll be able to figure out what is causing the crash and take it from there.

Community
  • 1
  • 1