【发布时间】:2017-12-21 04:47:18
【问题描述】:
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;
}
第一个问题是请求权限的弹出窗口由
[manager requestAlwaysAuthorization]; 在 0.5 秒~3 秒后被解除。我不知道它为什么会被解雇。
即使我按下总是批准(我不知道英文版到底是怎样的),
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。
【问题讨论】:
标签: objective-c cllocationmanager