How to secretly locate in the background: Request Background Location permissions:

Source: Internet
Author: User

"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. Instantiating the location Manager

_locationmanager = [[Cllocationmanager alloc] init];

2. Set up Proxy

_locationmanager.delegate = self;

3. Positioning accuracy

[_locationmanager Setdesiredaccuracy:kcllocationaccuracybest];

4. Request user rights: Divided into:? Only in the foreground to open the location, can also be located in the background,

Note: It is recommended to request only one, if two permissions are required, only request?

//?? This order will result in a bug: After the first start of the program, the system will only request the permissions of the?, the permission system will not be requested, only the next time the app is launched to request?

if ([[[[Uidevice Currentdevice] systemversion] Floatvalue] >= 8) {

[_locationmanager requestwheninuseauthorization];//? Only open the location at the front desk

[_locationmanager requestalwaysauthorization];//? can also be located in the background

}

5.ios9 new Features: 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 disabled at any time in the background location).

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:

How to secretly locate in the background: Request Background Location permissions:

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.