AppDelegate.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate,CLLocationManagerDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, strong) CLLocationManager * locationManager;
@property (nonatomic, strong) CLLocation *currentLocation;
@end
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSLog(@"11111");
CLLocationManager *manager = [[CLLocationManager alloc] init];
manager.delegate = self;
[manager requestAlwaysAuthorization];
//Here you set the Distance Filter that you need
manager.distanceFilter = kCLDistanceFilterNone;
// Here you set the Accuracy
manager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
NSLog(@"startUpdatingLocation");
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
NSLog(@"startUpdatingLocation %@" , status);
[manager startUpdatingLocation];
NSLog(@"22222");
return YES;
}
第一个问题是,在qsecxswpoi调用许可的弹出窗口在0.5秒~3秒之后被解雇。我不知道为什么要解雇。
即使我总是被批准(我不知道英文版本是如何确切的),[manager requestAlwaysAuthorization];
状态总是空的
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
其次
对于这个阶段, -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(CLLocation *)newLocation{
// currentLocation = newLocation;
NSLog(@"locationinfor %@! ,,, %@!!!!", newLocation.coordinate.latitude,newLocation.coordinate.longitude);
}
它应该去[manager startUpdatingLocation];
功能,应该记录didUpdateLocations
但它不来NSLog(@"locationinfor %@! ,,, %@!!!!", newLocation.coordinate.latitude,newLocation.coordinate.longitude);
。
问题可能是你宣布didUpdateLocations
。当你已经定义了一个类成员CLLocationManager *manager
时,为什么不使用它。
CLLocationManager *locationManager
编辑:确保您的Info.plist具有用户敏感数据的描述性文本。如果授权未确定,您还可以检查- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSLog(@"11111");
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager requestAlwaysAuthorization];
//Here you set the Distance Filter that you need
self.locationManager.distanceFilter = kCLDistanceFilterNone;
// Here you set the Accuracy
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
NSLog(@"startUpdatingLocation");
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
NSLog(@"startUpdatingLocation %@" , status);
[self.locationManager startUpdatingLocation];
NSLog(@"22222");
return YES;
}
并再次请求。
authorization status