ios - Xcode 更改我的应用程序的定位服务

标签 ios xcode ios-simulator core-location location-services

目前我有一个使用用户当前地理位置的应用程序。

每当我在我的设备或模拟器上运行该应用程序时,该应用程序都会打开并立即将我的定位服务从“已授权”变为“未确定”。出于某种原因,这只发生在我身上,而我的其他开发人员都没有。

我不确定这是我昨晚更新到 6.01 的 Xcode 的问题,还是我的代码中的某些问题。

我已尝试重置应用程序的定位服务,但当我返回应用程序时,它立即将其更改回“未确定”。

知道是什么导致了这个问题吗?有没有人遇到过类似的问题?

下面是我的 locationManager 的一段代码。

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
NSLog(@"did change status");

if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
    NSLog(@"not determined");

} else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized) {
    NSLog(@"Authorized");
    [[NSNotificationCenter defaultCenter] postNotificationName:@"Location Services Authorized" object:self];

} else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted){
    NSLog(@"restricted");
    [[NSNotificationCenter defaultCenter] postNotificationName:@"Location Services Restricted" object:self];

} else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
    NSLog(@"denied");
    [[NSNotificationCenter defaultCenter] postNotificationName:@"Location Services Denied" object:self];

} else {
    NSLog(@"can not");

最佳答案

我在您的代码中没有看到您调用 requestWhenInUseAuthorization 的位置。这在 iOS8 中是必需的,以便在位置服务工作之前请求用户授权。

每次启动位置服务时只需在位置管理器上调用它以确保您拥有权限(如果您已经拥有权限或权限已被拒绝,它什么也不做)。

关于ios - Xcode 更改我的应用程序的定位服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25949604/

相关文章:

ios - 如何快速将 UILabel 嵌入到 UIView 中

ios - UITableView 从其他 Viewcontroller 添加行

iOS swift : Pushing two view controllers when app launched from push notification

ios - Xcode 模拟器显示空白屏幕,直到退出调试器

ios - Cocos2D 中强制设备纵向显示

ios - Parse.com IOS,无法获取指向 PFUser 的指针

ios - 在 tableView 中处理异步 Firestore 数据读取 - iOS

ios - iOS 中的多个持久存储协调器

ios - dispatch_async 用于从 url 获取许多图像

ios - 在 Xcode 9 的 iPhone 模拟器中截图