IOS 8 Targeting issues

Source: Internet
Author: User

iOS8 Positioning Problems2014-10-09 09:50 1012 People read comments (0) favorite reports

Reprinted from: http://www.th7.cn/Program/IOS/201409/282090.shtml

There are two new methods for locating features in IOS8:

-(void) requestwheninuseauthorization __osx_available_starting (__mac_na, __iphone_8_0);-(void) Requestalwaysauthorization __osx_available_starting (__mac_na, __iphone_8_0);


These two new methods cause the previously written program to appear in IOS8, the location function is not working properly

So let iOS8 normal use positioning function?

<1> you need to add two variables to the Info.plist table

Add two default fields to the Info.plist

    • Nslocationalwaysusagedescription

    • Nslocationwheninuseusagedescription

These two fields are not particularly interesting in that they are customized to prompt the user for permission to use the geolocation feature.


This writes the code:

    Cllocationmanager  *locationmanager = [[Cllocationmanager alloc]init];    Locationmanager.delegate = self;    [Locationmanager requestalwaysauthorization];    Locationmanager.desiredaccuracy = kcllocationaccuracybest;    Locationmanager.distancefilter = Kcldistancefilternone;    [Locationmanager startupdatinglocation];


This is a call to the proxy

-(void) Locationmanager: (Cllocationmanager *) Manager didchangeauthorizationstatus: (clauthorizationstatus) Status {    switch (status) {case        kclauthorizationstatusnotdetermined:            if ([Locationmanager respondstoselector:@ Selector (requestalwaysauthorization)]) {                [Locationmanager requestwheninuseauthorization];            }            break;        Default: Break            ;    }}


This will be OK, the original cue box pops up

Today in the development of the discovery of a iOS8 location problem, after the operation, do not call to the delegate method after the location, and then found some information to understand the iOS8 system positioning, found that is really different:

Workaround:

1. Add key in Info.plist;

Nslocationwheninusedescription, allowing GPS descriptions to be obtained at the front desk
Nslocationalwaysusagedescription, allows the description of GPs to be acquired in the background

2. In code positioning, make the version distinction and authorization request:

[OBJC]View Plaincopyprint?
  1. if ([Cllocationmanager locationservicesenabled])
  2. {
  3. if (! Self. Locationmanager)
  4. {
  5. self. Locationmanager = [[Cllocationmanager alloc] init];
  6. }
  7. self. Locationmanager. Delegate = self ;
  8. self. Locationmanager. distancefilter=1. 0;
  9. self. Locationmanager. desiredaccuracy = kcllocationaccuracybest;
  10. if ([self. Locationmanager respondstoselector:@selector (requestalwaysauthorization)])
  11. {
  12. [self. Locationmanager requestalwaysauthorization]; //Permanent license
  13. [self. Locationmanager requestwheninuseauthorization]; //Authorized in use
  14. }
  15. [self. Locationmanager startupdatinglocation]; Turn on location updates
  16. self. Delegate = delegate;
  17. }


OK, fix it. The change also shows that Apple has begun to design a hierarchy of privacy authorizations that are no longer limited to the 2 option of 1. This is a good thing!

IOS 8 positioning problem (GO)

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.