【问题标题】:objective C . get lat/lng information on app delegate.m目标 C。获取有关 app delegate.m 的 lat/lng 信息
【发布时间】: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


    【解决方案1】:

    问题可能出在您对CLLocationManager *manager 的声明中。当您已经定义了一个类成员 CLLocationManager *locationManager 时,为什么不使用它。

    - (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;
    }
    

    编辑:确保您的 Info.plist 包含用户敏感数据的描述性文本。如果授权未确定,您也可以检查authorization status 并再次请求。

    - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
        if (status == kCLAuthorizationStatusNotDetermined) {
            [self.locationManager requestAlwaysAuthorization];
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-10
      • 2022-01-02
      • 1970-01-01
      • 2016-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多