swift – requestWhenInUseAuthorization()无法在iOS 8中使用Info.plist中的NSLocationWhenInUseUsageDescription键

swift – requestWhenInUseAuthorization()无法在iOS 8中使用Info.plist中的NSLocationWhenInUseUsageDescription键,第1张

概述我正在使用iOS SDK 8.1尝试调用requestWhenInUseAuthorization()方法来提示用户授予对我的应用程序的访问权限.我导入了CoreLocation.framework,并将NSLocationWhenInUseUsageDescription和NSLocationAlwaysUsageDescription键添加到info.plist中.当我运行应用程序时,它从未提 我正在使用iOS SDK 8.1尝试调用requestWhenInUseAuthorization()方法来提示用户授予对我的应用程序的访问权限.我导入了CoreLocation.framework,并将NSLocationWhenInUseUsageDescription和NSLocationAlwaysUsageDescription键添加到info.pList中.当我运行应用程序时,它从未提示我进行位置访问.以下是我的代码,我错过了什么?
import UIKitimport CoreLocationimport MapKitclass VIEwController: UIVIEwController,CLLocationManagerDelegate {    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        var manager = CLLocationManager()        manager.delegate = self        manager.desiredAccuracy = kCLLocationAccuracyBest        let authorizationStatus = CLLocationManager.authorizationStatus()        switch authorizationStatus {        case .Authorized:            println("authorized")        case .AuthorizeDWhenInUse:            println("authorized when in use")        case .DenIEd:            println("denIEd")        case .NotDetermined:            println("not determined")        case .Restricted:            println("restricted")        }        manager.requestWhenInUseAuthorization()        manager.startUpdatingLocation()    }    func locationManager(manager: CLLocationManager!,dIDUpdateLocations locations: [AnyObject]!) {        let location = locations[0] as CLLocation        println("Latitude: \(location.coordinate.latitude). Longitude: \(location.coordinate.longitude).")    }    func locationManager(manager: CLLocationManager!,dIDChangeAuthorizationStatus status: CLAuthorizationStatus) {        switch status {        case .Authorized:            println("authorized")        case .AuthorizeDWhenInUse:            println("authorized when in use")        case .DenIEd:            println("denIEd")        case .NotDetermined:            println("not determined")        case .Restricted:            println("restricted")        }    }    overrIDe func dIDReceiveMemoryWarning() {        super.dIDReceiveMemoryWarning()    }}

控制台只显示“未确定”一次,没有别的.所以我去了iPhone模拟器=>设置=>隐私=>位置=>我的应用程序它向我展示了3个选项:“从不”,“使用应用程序时”,“始终”.但没有选择任何东西.

问题解决了.我的经理在vIEwDIDLoad()方法中被声明为局部变量,但它应该是类级属性.

在我将经理声明移出vIEwDIDLoad()之后,我的应用程序运行了.

不确定manager.requestWhenInUseAuthorization()是如何在场景后面工作的,以及为什么vIEwDIDLoad()中定义的管理器不起作用.希望知道这个细节的人启发我.

总结

以上是内存溢出为你收集整理的swift – requestWhenInUseAuthorization()无法在iOS 8中使用Info.plist中的NSLocationWhenInUseUsageDescription键全部内容,希望文章能够帮你解决swift – requestWhenInUseAuthorization()无法在iOS 8中使用Info.plist中的NSLocationWhenInUseUsageDescription键所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1046752.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存