Http://www.cocoachina.com/ios/20150624/12200.html
Demo:github Address
"IOS9 on the problem of positioning, there is a bad news a good news" bad news: If not fit iOS9, you can not sneak in the background (without blue bar, see picture)! Good news: This scenario will be allowed: multiple location managers in the same app: some can only be located in the foreground, others can be located in the background, and can be turned on or off in the background of a particular location manager at any time.
If you do not have permission to request background targeting, you can also locate it in the background, but with a blue bar:
How to secretly locate in the background: Request Background Location permissions:
// 1. Instantiate location Manager _locationmanager = [[cllocationmanager alloc] init];// 2. setting Agent _locationmanager.delegate = self;// 3. positioning accuracy [_locationmanager Setdesiredaccuracy:kcllocationaccuracybest];// 4. Requesting user rights: Divided into:? Only in the foreground to open the location? In the background can also be located,//NOTE: It is recommended to request only? and, if two permissions are required, Only request, can,//?? This order will result in a bug: After the first start of the program, the system will only request the permissions of the?, the system does not request, only the next time the app is launched to request?if ([[[uidevice currentdevice] SYSTEMVERSION] FLOATVALUE] >= 8) { //[_locationManager requestwheninuseauthorization];//? Only open in front of the reception [_locationManager requestalwaysauthorization];//?}// 5.ios9 new features can be located in the background: This scenario will be allowed: multiple Location manager in the same app: some can only be located in the foreground, Others can be located in the background (and can be blocked from background positioning at any time). if ([[[Uidevice currentdevice] systemversion] floatvalue] >= 9] { _locationmanager.allowsbackgroundlocationupdates = yes;} 6. Update user Location [_locationmanager starTupdatinglocation];
But if you try this way, and you don't configure info.plist,100%, your program crashes and you get an error:
Assertion failure in-[cllocationmanager setallowsbackgroundlocationupdates:],/buildroot/library/caches/ com.apple.xbs/sources/corelocationframework_sim/corelocation-1808.1.5/framework/corelocation/ cllocationmanager.m:593
To configure the Info.plist as follows:
The corresponding Info.plist XML source code is:
IOS 9 Adaptation Series Tutorial: Background targeting