rwbutler / Updates

📲 Automatically detects app updates and seamlessly prompts users to upgrade.
https://medium.com/swlh/updating-users-to-the-latest-app-release-on-ios-ed96e4c76705
MIT License
289 stars 37 forks source link

Connection timeout when device is not connected to internet #13

Closed furiosFast closed 3 years ago

furiosFast commented 3 years ago

Hi, when the app call the Updates code and the device is not connected to internet, i've this error in console: Error Domain=AMSErrorDomain Code=203 \"Bag Load Failed\" UserInfo={NSLocalizedFailureReason=Unable to retrieve p2-product-offers-batch-limit because we failed to load the bag. The problem is in "Updates.swift" file at the code line 66

rwbutler commented 3 years ago

Hi @furiosFast, thanks for reporting this issue - please could you let me know what Xcode version you're using, which iOS simulator or device is being used as well as the Swift version please? Thanks in advance!

furiosFast commented 3 years ago

Hi, yes, of course!

rwbutler commented 3 years ago

Thanks for the additional information could I also ask - what issues are you seeing as a result of this error message - is the app information failing to load or is it simply that the error message is printed to the console? Line 66 is basically attempting to use StoreKit to automatically retrieve the correct country code for the user in order to retrieve the correct app information for the relevant App Store territory. One workaround would be to set the country code property manually perhaps setting to use Locale.current.regionCode which the property does fall back to in the event that is unable to retrieve the country code using StoreKit.

furiosFast commented 3 years ago

The problem is that in my app I do a check at startup to see if an update is available on the app store. This causes me to completely freeze the app for about 45/60 seconds (I think). I also tried to do:

Updates.countryCode = Local.current.regionCode
Updates.appStoreId = myAppId

but in any case the block, until the call times out, happens the same. This is because, if I'm not mistaken, on line 41 the countryCode is never passed as a parameter and therefore is set by default to nil in appStoreURL() in Updates+Internal.swift

rwbutler commented 3 years ago

Hi @furiosFast, your setting should take effect because the first line in appStoreURL is:

static func appStoreURL(appStoreId: String, countryCode: String? = nil, productName: String) -> URL? {
        guard let countryCode = countryCode ?? Updates.countryCode else {
            return nil
        }

However the countryCode property will still be accessed because it is static therefore the initialisation block will be run before the value you set is applied. Therefore I've added a flag named useStoreKit - if you set this to false could you tell me whether this resolves the issue please?

furiosFast commented 3 years ago

HI, I have implemented and set the new flag, but I can only give you an answer on Friday, as until Friday I have no iPhone 7 to test. I'll hang up. In the meantime, thank you!

rwbutler commented 3 years ago

No problem - thanks for the update, will wait to hear back. Hopefully this will resolve the issue for you.

furiosFast commented 3 years ago

Hi, the problem seems to be solved.

Thanks again for the support

rwbutler commented 3 years ago

That's great to hear thanks glad it's working for you 👍🏻