ios - 位置服务警告,即使它们已启用

标签 ios cocoa-touch

if (kCLAuthorizationStatusDenied) {
    UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:@"Location Services Disabled" message:@" Please go to settings  and enable them if you want to use all the features of this app  " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [servicesDisabledAlert show];
}

即使启用了位置服务,也会弹出警报。

此代码放在 AppDelegate 的 application didFinishLaunchingWithOptions: 方法中。

最佳答案

你正在检查一个常量不为 nil,它永远为真

您需要查看当前的授权状态:

if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied)

编辑:RazorSharp 提出了一个很好的观点。驼峰式但以小写 k 开头的东西通常是常量

关于ios - 位置服务警告,即使它们已启用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20021242/

相关文章:

ios - 使用 multiply 和 alpha 在另一个 GPUImage 上绘制

ios - 在 ios 应用程序中使用 googleapis

ios - Swift - 在 AppDelegate 中实例化 View Controller

ios - 我的 setBackgroundColor 总是与 photoshop 不同

objective-c - 区分对同一委托(delegate)方法的调用

ios - XCode 6.3 Alamofire.swift 文件崩溃

ios - NSNotificationCreation 会影响应用程序性能吗?

iphone - UIView和内存管理

iphone - 如何在 iPhone 上将 UIWebView 的内容居中

ios - 如何将透视变换应用于 UIView?