robotmedia / RMStore

A lightweight iOS library for In-App Purchases
Apache License 2.0
2.42k stars 450 forks source link

Crashes in `RMKeychainGetValue` #217

Closed aalenliang closed 6 years ago

aalenliang commented 6 years ago

I'm using RMStore for my iOS project, which is written in Swift. In last two days I receive many (like 88 times) crash logs, affects 5 users:

#0. Crashed: com.apple.main-thread
0  libswiftCore.dylib             0x104033968 specialized _assertionFailure(StaticString, String, file : StaticString, line : UInt, flags : UInt32) -> Never (__hidden#23281_:134)
1  libswiftCore.dylib             0x103ee3994 swift_errorInMain (__hidden#23992_:186)
2  pricetagframework              0x1034e1b8c RMKeychainGetValue + 955328
.......

And I looked in crash history, this crash happens since last two versions, from iOS 10.3.3 to iOS 11.2.2, I can't reproduce it, not sure if it's relates to this library.

Here is my code, I get my product information and verifies it when my app starts.

class ItunesModule {
    public static let shared = ItunesModule()

    init() {
        getProductInfo {
            self.verifyReceipt()
        }
    }

    public func getProductInfo(callback: @escaping () -> Void) {
        if let product = Product('identifier') // Product is a struct contains information like SKProduct.

        RMStore.default().requestProducts(
            [product.identifier],
            success: { [weak self] results, _ in
                if let products = results as? [SKProduct] {
                    if let result = (products.filter { $0.productIdentifier == product.identifier }).first {
                        product.localizedTitle = result.localizedTitle
                        product.localizedDescription = result.localizedDescription
                        product.price = result.price

                        self?.product = product
                        self?.postNotification(named: NotificationName.didRetrieveGoProInfo)

                        callback()
                    }
                }
            },
            failure: { error in
                log.error(error.debugDescription)
            }
        )
    }

    func verifyReceipt() {
        if let receipt = RMAppReceipt.bundle() {
            product.available = verify(product, inReceipt: receipt)
        }
    }

    func verify(_ product: Product, inReceipt receipt: RMAppReceipt) -> Bool {
        return receipt.bundleIdentifier == Bundle.mainBundleIdentifier &&
            receipt.verifyReceiptHash() &&
            receipt.inAppPurchases.count > 0 &&
            receipt.contains(inAppPurchaseOfProductIdentifier: product.identifier)
    }
}
aalenliang commented 6 years ago

Look inside the log I realize it's nothing about RMStore, sorry.