简体   繁体   中英

Cordova iOS onResume firing at startup and crashing app

I'm currently just building for iOS 8+ and I'm testing on an iPhone 6, and 6S+ in the emulator. I'm using the command line to build and run, and I'm using the Cordova CLI. I've also dipped into XCode a few times to check capabilities, or fix provisioning issues.

This isn't the first app I've build using Cordova, and I've previously been able to use the resume event without issue.

I'm using document.addEventListener("resume", onResume(), false); to fire certain functions when my app resumes. However this function is firing on first launch, and not firing at all on startup. It seems to be anytime the resume function fires it crashes my app.

I've reduced my app down to bare bones, nothing is happening in the onResume function now except the following:

function onResume() {
    setTimeout(function(){
        console.log('App resumed');
    },0);   
}

Going a little out of my mind here. I have the following plugins installed.

  • com.telerik.plugins.healthkit 0.4.2 "HealthKit"
  • cordova-plugin-console 1.0.2 "Console"
  • cordova-plugin-splashscreen 3.1.0 "Splashscreen"
  • cordova-plugin-statusbar 2.1.1 "StatusBar"
  • cordova-plugin-webserver 1.0.3 "CordovaWebServer"
  • cordova-plugin-whitelist 1.2.1 "Whitelist"

Managed to fix this problem, though not sure what I'd done wrong. I can only assume I must have had the wrong event name in place, or in my attempts to fix it I'd added another problem before fixing the previous one. Either way something I'd done wrong had caused the issue.

Things to check yourself:

  • Your document.addEventListener('resume', onResume, false); event listener is in code run after device ready has fired.
  • The function you are calling doesn't include the (). Eg onResume , not onResume() .
  • You've only included a function name and nothing else in the resume event listener.
  • The function you're calling includes a setTimeout of 0ms to get around iOS quirks.
  • You've spelled your functions and resume event correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM