gpt4 book ai didi

ios - 检查接受 NSLocationWhenInUseUsageDescription

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:26:28 24 4
gpt4 key购买 nike

我正在为处理信标和位置管理的 iOS 开发应用程序。在 iOS 8 中,应用程序必须在 plist 文件中包含“NSLocationWhenInUseUsageDescription”键,该键将在启动时显示在应用程序中,以获取用户启用位置跟踪的权限。如何检测用户是否接受?我想就此做出决定。

谢谢。

最佳答案

您可以通过在类设置中实现以下方法作为您的 CLLocationManager 委托(delegate)(实现 CLLocationManagerDelegate 协议(protocol))来检测这一点

Swift 中的示例:

// MARK: CLLocationManagerDelegate

func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
// check status to see if we’re authorized
let authorized = (status == CLAuthorizationStatus.AuthorizedWhenInUse)
// handle acceptance...
}

objective-c 示例:

-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {

BOOL isAuthorized = status == kCLAuthorizationStatusAuthorizedWhenInUse;
// handle acceptance..
}

关于ios - 检查接受 NSLocationWhenInUseUsageDescription,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28848761/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com