iOS background positioning implementation(2013-01-24 16:43:12)Encounter a position in the work of the application scenario: The app needs to run in the background, real-time upload user location. Apple's standard of iOS has increased the quality of the app while also bringing developers to the limits. Through a variety of official documents and materials, concluded as follows: 1, to achieve background positioning there are 2 ways:
- Standard Location Service (call Cllocationmanager's startupdatinglocation)
- Significant-change Location Service (call Cllocationmanager's startmonitoringsignificantlocationchanges)
2, the difference between the two:
- The former (startupdatinglocation) is the standard positioning, want to use in the background must add required background modes attribute in the Info.plist file, and select the app registers for Location updates value.
- The former (startupdatinglocation) runs in the background and may be suspended (suspend) or terminated (terminate) by the system because of a resource problem, but once an update is aroused, the system is still resource-intensive when it is updated. The delegate will be deferred. It is difficult to control the performance of the user's machine if the requirements for real-time are high and may not be suitable for this.
- The former (startupdatinglocation) is no longer awakened if it is manually closed by the user.
- The former position is based on the gps/base station/wifi positioning, the specific use of which corelocation framework has its own rules.
- The latter (startmonitoringsignificantlocationchanges) is used to locate the base station, so the device must have a telephone module, in the plist can set the XX attribute to limit the device can be downloaded and installed.
- The latter (startmonitoringsignificantlocationchanges), whether in the background or manually closed by the user, is invoked by the calling delegate, and there are only 3 ways to prevent it from being updated. (1) The user closes the location service (2) the user shuts down the app's location Service (3) the device is in airplane mode or cannot turn on the necessary hardware (guess the hardware that locates the module).
- When does the latter (startmonitoringsignificantlocationchanges) update? is updated when the base station is replaced. So the update frequency is related to the base station density. Urban renewal frequency is higher than the suburbs. So many students say that there is no update because it is still within the same set of base stations.
- The former is less expensive and more accurate than the latter.
3, the two common:
- Both update the location information when both callback the same delegate method:-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations;
4. Upload information:
Because the background task allocates only a limited amount of time to perform the necessary actions, the app will be terminated if it is not completed before the time-out (such as a network request). Here's a way to ask for an extra 10 minutes to get you to do what you want, request a background task: Beginbackgroundtaskwithexpirationhandler (not detailed, use the method can check the information).
5. Summary:
2 ways each have pros and cons, depending on the use of the scene and decided that the front-run app often requires accurate real-time positioning, and run time is limited, consider the first standard positioning, such as navigation applications. If the movement is fast (the distance changes significantly), long-time positioning (monitoring), you can consider the latter, such as a taxi application.
Reference
[1]http://www.mindsizzlers.com/2011/07/ios-background-location/
[2]https://developer.apple.com/library/ios/#documentation/userexperience/conceptual/locationawarenesspg/ Corelocation/corelocation.html
iOS background positioning implementation