apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.15k stars 987 forks source link

Cordova-iOS 6.2.0 App doesn't load on iPhone 8 Plus - iPhone 14 (Simulators) #1306

Closed cemerson closed 1 year ago

cemerson commented 1 year ago

Bug Report

Problem

My app fails to load on iOS Simulators iPhone 8 Plus or higher (up to 14) but works fine on the iPhone 6, 7 and 8.

App DOES load up successfully my Cordova index.html page (and scripts, etc) when I use the following iOS simulators:

App DOES NOT load/show my Cordova index.html page (and scripts, etc) when I use the following iOS simulators:

What is expected to happen?

What does actually happen?

Information

The logs for when the app works vs doesn't work are nearly identical as far as I can tell and no errors show up in the logs either.

No errors show up in the Xcode debug logs however somewhat interesting that when the app fails to load it appears the app never loads any of my javascript that normally loads (I know this because none of the usual console.log stuff shows up)

FWIW the Android build of the same app, same code works fine in simulators and on devices

Here is the full XCode log for when the app fails to load:

MyApp: Apache Cordova native platform version 6.2.0 is starting.
MyApp: Multi-tasking -> Device: YES, App: YES
MyApp: Could not load the "LaunchStoryboard" image referenced from a nib in the bundle with identifier "com.mycompany.myapp"
MyApp: The preference key "AllowNewWindows" is not defined and will default to "FALSE"
MyApp: The preference key "MediaPlaybackAllowsAirPlay" is not defined and will default to "TRUE"
MyApp: The preference key "AllowBackForwardNavigationGestures" is not defined and will default to "FALSE"
MyApp: The preference key "Allow3DTouchLinkPreview" is not defined and will default to "TRUE"
MyApp: CDVWebViewEngine will reload WKWebView if required on resume
MyApp: Using WKWebView
MyApp: [CDVTimer][console] 0.063896ms
MyApp: [CDVTimer][handleopenurl] 0.052094ms
MyApp: Unlimited access to network resources
MyApp: Unlimited access to network resources
MyApp: [CDVTimer][intentandnavigationfilter] 1.314044ms
MyApp: [CDVTimer][gesturehandler] 0.060916ms
MyApp: [CDVTimer][file] 21.870017ms
MyApp: [CDVTimer][inappbrowser] 0.114083ms
MyApp: [CDVTimer][statusbar] 1.536012ms
MyApp: WARNING: NativeXHR is allowing untrusted certificates due to preference AllowUntrustedCerts=on
MyApp: [CDVTimer][cdvwkwebviewfilexhr] 1.183033ms
MyApp: [CDVTimer][TotalPluginStartup] 27.620077ms
MyApp: WF: === Starting WebFilter logging for process MyApp
MyApp: WF: _userSettingsForUser : (null)
MyApp: WF: _WebFilterIsActive returning: NO
MyApp: IAB.close() called but it was already closed.
MyApp: The preference key "AutoHideSplashScreen" is not defined and will default to "TRUE"
MyApp: SecureDeviceIdentifier.js loaded...
(NOTE:  HERE Is where my normally Javascript would start doing console.logs ... but the log ends here)

Command or Code

No code changes between when the app works or doesn't work - it's simply based on which iOS iPhone Simulator I use

Environment, Platform, Device

Version information

Checklist

PS: I hate to post an issue here but I am quite stumped w/this one and it's very challenging to find help on Google, StackOverflow, etc given how generic the issue is. My apologies in advance if this issue is some dumb mistake on my end.

breautek commented 1 year ago

Can you reproduce this with a simple hello world cordova app? You have several plugins any one of them could be influencing the problem.

FWIW, On XCode 14.3 iPhone 14 simulator running iOS 16.4 doesn't appear to produce the problem for me. I also tested the same simulator but iOS 16.2, but the hello world app does run. Xcode 14.3 doesn't ship with Phone 8 Plus or iPhone X simulators, so I didn't test those ones.

So what this tells me is the cordova framework at the basic level works... but

  1. The problem could be exposed by a certain configuration
  2. The problem could be exposed by a plugin, or a combination of plugins.
  3. The problem is actually in one of the installed plugins.

It is definitely strange to hear that it works in some simulators but not others. Assuming the same iOS version, I would have thought the only difference between simulators is screen resolution rendering.

cemerson commented 1 year ago

Thank you so much for replying. Good point / suggestions there.

So, as you suggest, the issue does likely lie somewhere in my configuration or my scripts I suppose. I will continue trying to find the culprit and will report back if/when I find the issue. Thank you again for your reply.

image

breautek commented 1 year ago

Just a bit more information that may help...

MyApp: [CDVTimer][TotalPluginStartup] 27.620077ms
MyApp: WF: === Starting WebFilter logging for process MyApp
MyApp: WF: _userSettingsForUser : (null)
MyApp: WF: _WebFilterIsActive returning: NO
MyApp: IAB.close() called but it was already closed.
MyApp: The preference key "AutoHideSplashScreen" is not defined and will default to "TRUE"
MyApp: SecureDeviceIdentifier.js loaded...
(NOTE:  HERE Is where my normally Javascript would start doing console.logs ... but the log ends here)

Here, at the TotalPluginStartup line, I believe is when all plugins has ran through their initialisation code. At this point or soon after you should have received a deviceready event triggered, which based on the logging afterwards, I believe that might the case.

If deviceready did fire, then as far as cordova is concerned, everything got initialized. Plugins may have further initialisation cause they can listen onto deviceready themselves or whatever, but it will be on the plugin to notify somehow when it's ready.

So my comments yesterday might be a red herring. If the deviceready did fire, then something on the JS side must be hanging preventing your app from initializing properly. I'm not sure how extensive your testing was with the different simulators but it could be a race condition and the actual simulator doesn't matter.

So here is what I'd probably do...

  1. Launch the app and open up Safari Web Inspector
  2. Set your breakpoints in your startup/bootstrap code. Everyone of them if you have multiple deviceready event listeners. If the issue is indeed a race condition, hopefully it will break (or the act of pausing the JS execution may "eliminate" the race condition causing it to always work while stepping through the code slowly.)
  3. Since you're debugging startup code, you'll need to use cmd+r while the Safari Inspector is focused to refresh/reload the webview. Now... a refresh isn't necessary the same as an app launch, for example plugins may not "re-initialize" natively so to speak, it depends on the Plugin's implementation. So refreshing may introduce other side effects. Just something to keep in mind.

As you walk through your code... basically what you're looking for is when it may randomly stop executing unexpectedly. You may be doing an asynchronous call to the plugin that you're awaiting a response on and that is never coming back (for whatever reason). If you can find this, then it will probably at least lead you to where to spend your attention on.

Also another hint... but if have some infinite loop being triggered somehow, you may be able to detect that simply by hitting the "Pause" button in the inspector, which will cause the JS engine to break at the next executing statement. If the engine is at an idle, then it won't break until a JS line executes somewhere. If it's busy in a loop, it should breakpoint immediately. This technique doesn't work well however if you have timers page or some other constant JS executing frequently.

cemerson commented 1 year ago

Thank you for such a quick (and helpful) second reply!

Using your advice (Safari Web Inspecting + iOS Simulator) I was able to find a error in one of my main JS files (outside any try/catch/console logs) that seem to be what was choking up the iOS simulators that weren't working yet. I'm not sure how/why some iOS simulators were able to forgive/move past the error and some weren't but in any case it looks like they're all working now.

Naturally I'm quite embarrassed that the issue was my fault not (really) a Cordova issue but thank you so much for your help and guidance helping me resolve it. Very much appreciated. 🙏🏻

breautek commented 1 year ago

No problem.

The art of programming is really about how well you can debug ;)

I'm not sure how/why some iOS simulators were able to forgive/move past the error

Yup, that also stumps me, but at least it appears to be working now.

cemerson commented 1 year ago

So true. If I had nickel for every time a mysterious code issue traced back to a lack of or faulty try/catch/debug setup ...