我解决了一个问题,即GPS服务在iOS 7上完美运行,但在iOS 8上,我从未获得权限请求和方法:
- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
Run Code Online (Sandbox Code Playgroud)
永远不会被召唤.
我的代码在这里:
#import "Locator.h"
@implementation Locator
- (instancetype) init {
if (self = [super init]) {
// Start up the location manager
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = 3;
// New property for iOS6
if ([self.locationManager respondsToSelector:@selector(activityType)]) {
self.locationManager.activityType = CLActivityTypeFitness;
}
// New method for iOS8
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
}
}
return self;
}
- (void) startMonitoring:(LocationChangeCallback)callback {
if ([CLLocationManager …Run Code Online (Sandbox Code Playgroud) #import "MyLocationViewController.h"
#define NSLog(FORMAT, ...) printf("%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
@interface MyLocationViewController ()
@end
@implementation MyLocationViewController
{
CLLocationManager *locationManager;
}
- (void)requestAlwaysAuthorization
{
[locationManager requestAlwaysAuthorization];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.mapView.showsUserLocation = YES;
self.mapView.delegate = self;
locationManager = [[CLLocationManager alloc] init];
}
- (IBAction)unwindToMap:(UIStoryboardSegue *)segue
{
}
- (IBAction)getCurrentLocation:(id)sender {
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
MKCoordinateRegion …Run Code Online (Sandbox Code Playgroud)