cowbell / cordova-plugin-geofence

Geofencing plugin for cordova
Apache License 2.0
265 stars 318 forks source link

Using WkWebWkit disables javascript execution/callback when app enters background #127

Open johnrobertcobbold opened 8 years ago

johnrobertcobbold commented 8 years ago

Have been bumping my head for the past 36h on this and I finally seem to understand what is going on. I don't see any solution but perhaps this can stir some discussion / help others.

Using UIview and this plugin, I can successfully do the following when a geofence receives a transition : 1> Trigger a JS callback when the app is in the foreground 2> Trigger a JS callback when the app is in the background (user pressed home button, app is still alive) 3> Trigger a JS callback when the app was terminated (by user or OS)

However, after implementing WkWebWkit with Cordova iOS 4, cordova-plugin-wkwebview-engine and the master version of cordova-plugin-geofence, I realize that 2> does not work anymore... From what I understand after some research is that WKWebView changes the way javascript runs (separate process?) and all JS execution is stopped when the app is backgrounded. Case 3> still works as the OS launches the app from scratch.

After removing WkWebWkit and switching back to using UIView, it's all back to normal and 2> works once again. I am slightly surprised as no-one seems to be discussing this ? I am the only one to use custom JS callbacks ?

Some relevant material encountered during my research : http://stackoverflow.com/questions/26514090/wkwebview-does-not-run-javascriptxml-http-request-with-out-adding-a-parent-vie http://www.openradar.me/17680867

riegeljonez commented 8 years ago

Hi @johnrobertcobbold, two questions on your findings:

I updated to cordova iOS 4 – do I now automatically use WKWebView instead of UIWebView or whats the matter with the cordova-plugin-wkwebview-engine plugin?

Respectively: How/Where did you remove WKWebView and switched back to UIView?

As I'm getting the failure notice #123 I'm assuming I'm using it, do I?

johnrobertcobbold commented 8 years ago

You need to install cordova-plugin-wkwebview-engine plugin to use WKWebView otherwise it will default to UIWebView. Even if you are using UIWebView, this plugin has an issue on the latest master version like described in https://github.com/cowbell/cordova-plugin-geofence/issues/122 - Tempus35 suggestd a fix that works.

Wade-BuildOtto commented 7 years ago

I have the same issue, I am going to try the UIwebview and see if that fixes the issue knowing that it breaks Hot-code pushes. but if it makes the app work again then I guess it might be worth it.

Wade-BuildOtto commented 7 years ago

This didn't seem to work, the url is back to http://localhost so I am pretty sure its back to UIWebView, but the app got kicked out and failed to reload and execute. I will try further but it really depends on the devices use.

hreimer commented 6 years ago

@goyavo this thread is over a year old, but did you manage to get it working / remember what the solution was, if there was any? I have a similar use-case (tracking users location and play audio and load data when they reach a geofence, works well in foreground on iOS and Android, and in background in Android (i use the cordova-plugin-background-mode), but not in iOS. I see the logs with updating the position, and also the js code is executed up until where a $http.get request has to be done, suddenly the file can't be loaded (I use the cordova-labs-local-webserver as well, to serve the files needed for the Ionic 1 App). I've been searching the whole weekend how to overcome this bug, was wondering if you had any hints

Wade-BuildOtto commented 6 years ago

On IOS the app fails to reLaunch in order to process the transition change. This need to be remodelled to have the Plugin talk directly back to the server via API bypassing the need to reload the web server.