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
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?
- if ([Cllocationmanager locationservicesenabled])
- {
- if (! Self. Locationmanager)
- {
- self. Locationmanager = [[Cllocationmanager alloc] init];
- }
- self. Locationmanager. Delegate = self ;
- self. Locationmanager. distancefilter=1. 0;
- self. Locationmanager. desiredaccuracy = kcllocationaccuracybest;
- if ([self. Locationmanager respondstoselector:@selector (requestalwaysauthorization)])
- {
- [self. Locationmanager requestalwaysauthorization]; //Permanent license
- [self. Locationmanager requestwheninuseauthorization]; //Authorized in use
- }
- [self. Locationmanager startupdatinglocation]; Turn on location updates
- self. Delegate = delegate;
- }
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)