问题
I'm using MobileFirst Platform 6.3, I'm trying to implement a Hybrid Application for Android and iOS, where I have created enter/exit location triggers in it, with "enableHighAccuracy=true", the application should always listen to the triggers when it is in the foreground and background.
After adding the right permissions for both environments (Android, iOS), as stated in the KnowledgeCenter link: http://www-01.ibm.com/support/knowledgecenter/SSHS8R_6.3.0/com.ibm.worklight.dev.doc/dev/r_wl_location.html?lang=en
I have tested the app in Android and it is working as expected, when it is in the foreground and background, where I just log a message in the LogCat when the geo location trigger is acquired.
While in iOS, it does not work as expected. It works correctly in the foreground, but not in the background. I was testing using the iPhone Simulator of XCode, it does not log the messages in the XCode Console when it is in the background. However when I have checked the Privacy Settings in the Simulator , it indicated that the app has permissions to acquire the location "Always , in foreground and background"!!
Please advice, if there is another setting that should be made to make it work in iOS, and if it is a normal behavior that the logging does not work when the app is running in the background?
回答1:
First see this for how to set permissions to run location services in the background: Background Location Services not working in iOS 7
There is limitations in Ios. After couple of minutes of running in the background without any location update the app get suspend and all the location update will be received once the user bring the app back to life.
回答2:
The Answer is in iOS if you want the app to work in the background, DO NOT USE alerts, as it makes the app to stop at each alert trying to execute it. That does not happen in Android. So when I have removed the alerts in the callback of the location triggers, it worked fine logging in the console and acquiring the location normally.
来源:https://stackoverflow.com/questions/28962176/mobilefirst-6-3-enabling-location-trigger-in-background-in-hybrid-applications