无法在城市飞艇中获得位置启用YES



我需要启动定位服务,以便根据位置向设备发送推送。我使用分段来设置位置和时间,但我可以在日志中看到的是:

[UALocationService reportCurrentLocation] [Line 358] Location service not authorized or not enabled.

我的应用程序的info.plist中确实有NSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescription密钥。

我找不到导致该位置未启用的问题。任何帮助都将不胜感激。谢谢

代码:

self.locationManager = [[CLLocationManager alloc] init];
   if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
        [self.locationManager requestWhenInUseAuthorization];
    }
    [self.locationManager startUpdatingLocation];
    [UALocationService locationServicesEnabled];
    [UALocationService locationServiceAuthorized];
    [UALocationService airshipLocationServiceEnabled];
    UALocationService *locationService = [UAirship shared].locationService;
    [locationService reportCurrentLocation];
    [locationService startReportingSignificantLocationChanges];

经过搜索,我发现我们不需要自己添加CLLocationManager。

而是利用函数coreLocationWillPromptUserForPermissionToRun像这样:

[UALocationService coreLocationWillPromptUserForPermissionToRun];

以下是我们需要调用以启用服务的功能:

   [UALocationService airshipLocationServiceEnabled];
   [UALocationService setAirshipLocationServiceEnabled:YES];
   [UALocationService locationServicesEnabled];
   [UALocationService locationServiceAuthorized];
   [UALocationService coreLocationWillPromptUserForPermissionToRun];

最新更新