tikhop / TPInAppReceipt

Reading and Validating In App Purchase Receipt Locally.
MIT License
631 stars 93 forks source link

This method should not be called on the main thread as it may lead to UI unresponsiveness. #119

Open geoffroymorel opened 6 months ago

geoffroymorel commented 6 months ago

Hello,

I am getting the following double warnings in the console leading to an unresponsive UI for a couple seconds.

Warning is triggered when calling SecTrustEvaluateWithError in checkChainOfTrust() function after calling receipt.validate().

I have found the following on stackoverflow.com: https://stackoverflow.com/questions/73892668/sectrustevaluatewitherror-leads-to-ui-unresponsiveness

Xcode 15.2 iPhone 15 Pro Max iOS 17.3.1

Capture d’écran 2024-02-20 à 15 38 01
geoffroymorel commented 6 months ago

The actual freeze was not related to this issue. But the warnings are still showing up.

tikhop commented 6 months ago

@geoffroymorel Thanks for bringing this up. You can validate your receipt in any thread you want.

Personally, I just call validate method from background thread and it works without the warning message:

let receipt = ...
DispatchQueue.global(qos: .background).async {
    do {
        try receipt.validate()
        DispatchQueue.main.async {
            // Go back to the main thread
        }
    } catch {
        // Catch the error
    }
}

I will think about adding an async validate method and move the validation logic out of the main thread at lib level.