无法在Urban Airship中获得位置启用YES(Unable to get Location Enabled YES in Urban Airship)

编程入门 行业动态 更新时间:2024-10-28 00:23:24
无法在Urban Airship中获得位置启用YES(Unable to get Location Enabled YES in Urban Airship)

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

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

I need to get Location services up to send push to the device based on the location . I am using segments to set the location and the time but what I can see in my logs is :

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

I do have NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription keys in my application’s info.plist.

I am not able to find the issue causing the location not enabled. Any help will be appreciated. Thanks.

Code :

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

After Searching , I found that we do not need to add CLLocationManager on our own .

Instead make use of function coreLocationWillPromptUserForPermissionToRun like this:

[UALocationService coreLocationWillPromptUserForPermissionToRun];

Following are the functions that we need to invoke to enable services:

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

更多推荐

本文发布于:2023-08-03 02:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1382899.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   Airship   Urban   Enabled   Location

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!