我需要获取位置服务以根据位置向设备发送推送。 我正在使用段来设置位置和时间,但我在日志中看到的是:
[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。
[UALocationService coreLocationWillPromptUserForPermissionToRun];而是像这样使用函数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 .
[UALocationService coreLocationWillPromptUserForPermissionToRun];Instead make use of function coreLocationWillPromptUserForPermissionToRun like this:
Following are the functions that we need to invoke to enable services:
[UALocationService airshipLocationServiceEnabled]; [UALocationService setAirshipLocationServiceEnabled:YES]; [UALocationService locationServicesEnabled]; [UALocationService locationServiceAuthorized]; [UALocationService coreLocationWillPromptUserForPermissionToRun];更多推荐
发布评论