【问题标题】:Unable to get Location Enabled YES in Urban Airship无法在 Urban Airship 中启用位置 YES
【发布时间】:2015-07-28 10:17:39
【问题描述】:

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

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

我的应用程序的 info.plist 中有 NSLocationAlwaysUsageDescription 和 NSLocationWhenInUseUsageDescription 键。

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

代码:

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];

【问题讨论】:

  • 您可以为位置管理器放置代码吗?
  • @cyberlobe 我已经添加了代码。请检查。
  • 确保在 UALocationService.m iOS 8 中添加位置验证,如下所示:requestWhenInUseAuthorization 如果它的旧文件比用新文件更新它。
  • @cyberlobe 我在我的项目中找不到 UALocationService.m。有 UALocationService.h。

标签: ios urbanairship.com


【解决方案1】:

搜索后发现我们不需要自己添加CLLocationManager。

改为使用函数 coreLocationWillPromptUserForPermissionToRun 像这样:

[UALocationService coreLocationWillPromptUserForPermissionToRun];

以下是我们需要调用以启用服务的函数:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    • 2013-07-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多