IOS 9 Adaptation Series Tutorial: Background targeting

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.