简体   繁体   中英

Phonegap every 5 minutes wake app in background to check location iOS

I'm building a location-aware app in Phonegap that has to check location periodically in the background to determine when user enters/exits specific places. This question is about iOS specifically. The Significant-change API is no good for me because it's accuracy level is like more street-wise then building-wise, and the latter is what the app requires.

So far, after reading the comments in the great answer to this , I've managed to keep the app alive in background with a combination of this background mode declaration ( in config.xml ):

<gap:config-file platform="ios" parent="UIBackgroundModes" mode="replace">
    <array>
        <string>location</string>
    </array>
</gap:config-file>

and once when the app is in foreground after it was launched, calling:

navigator.geolocation.watchPosition(...)

What I need is:

  1. The app to be fully suspended between intervals (as it will kill the battery to have the app alive in BG under watchPosition all day long), and woken up just to perform a single getcurrentPosition + POST to a server each time.
  2. The app to be launched into that routine right from device boot .

So:

I figured what I would like is perhaps what they talk about in here (but that is native and regardless to Phonegap...).

What whould be the best strategy to achieve this in the Phonegap way?

Do you guys know a plugin or a combination of plugins to make it possible?

Should I abuse timed remote notifications to make the app wake up (heard it may be possible, don't know how apple will approve that...)

Or must I make my own plugin for this purpose?

Any advice or experience will be appreciated.

As for what I got to learn through the months passed after asking that Q, it's impossible to wake an app in background on a timed interval in iOS.

The best solution I could eventually find:

As I stated in the Q, my objective was to determine when user enters/exists specific places (buildings, actually). The best way possible to address this is the Region Monitoring API in iOS which wakes up the app in background once the device enters specific geographical regions predetermined by the app. It has some limitations though but we are trying various optimizations to somewhat overcome them.

A few plugins for cordova exists, this is the one I chose eventually: https://github.com/cowbell/cordova-plugin-geofence

Took some time to implement...

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