为什么我的应用程序在App Store上崩溃但未在开发中崩溃?

时间:2017-02-20 21:43:48

标签: ios swift in-app-purchase subscription auto-renewing

我怀疑它与基于订阅的应用内购买有关。一切都在开发模式和TestFlight上运行良好,甚至运行Ad Hoc。但是当它到达App Store时,它每次都会崩溃。

我已经检查了崩溃日志,我收到的唯一信息是它是一个SIGTRAP。

我认为这是在这段代码中:

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

}

2 个答案:

答案 0 :(得分:1)

您可以将Crashlytics集成到您的应用中,下次如果应用会在应用商店崩溃,您会在应用崩溃的电子邮件中获得课程名称和行号。

答案 1 :(得分:1)

您可以通过symbolicating your crash report找到崩溃线。

当你这样做时,你将能够找出导致崩溃的原因并将其从那里拿走。