ios - 没有获得位置 iOS8 的授权

标签 ios swift location cllocationmanager

我尝试寻找其他解决方案,例如:requestWhenInUseAuthorization() not Work in iOS 8 With NSLocationWhenInUseUsageDescription Key in Info.plist

但我无法获得获取位置的授权提示。

那个人在另一个问题中的问题是他的 viewDidLoad 中有经理,我没有,但仍然没有显示授权提示。我已经更新了我的 plist:

gyazo.com/b66946b9976aa226a21c0bf6e3817e3a

并让我的经理在我的 viewDidLoad 之外:

import UIKit
import AVFoundation
import MapKit

class SecondViewController: UIViewController, CLLocationManagerDelegate {

let locationManager: CLLocationManager = CLLocationManager()


var player = AVPlayer()
override func viewDidLoad() {
    super.viewDidLoad()
    self.locationManager.delegate = self
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
    self.locationManager.requestWhenInUseAuthorization()
    self.locationManager.startUpdatingLocation()
    println("Got to end of locationmanager")
    //playentryaudio() // User plugged in mic -- start playing entry audio.
}

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
    println("Got to locationmngsr")
    var userlocation = locations[0] as! CLLocation

    var latitude: CLLocationDegrees = userlocation.coordinate.latitude

    var longitude: CLLocationDegrees = userlocation.coordinate.longitude

    println(latitude)
    println(longitude)
} //snip rest of code

由于它没有获得身份验证,因此它永远不会调用 locationManager 函数。

最佳答案

提示仅在 CLLocationManager.authorizationStatus() == .NotDetermined 时显示。如果用户之前拒绝访问,您将不会再看到提示。您应该在 self.locationManager.requestWhenInUseAuthorization() 之前检查状态。如果它显示除 .NotDetermined 之外的任何内容,请查看应用和设备的位置设置。

如果状态为 .NotDetermined 并且提示仍未显示,我会仔细检查 NSLocationWhenInUseUsageDescription 的拼写。

关于ios - 没有获得位置 iOS8 的授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32169210/

相关文章:

flutter - 是否可以通过 flutter app 共享您的位置

java - 即使我有 wifi 和移动数据,在室内时 isNetworkEnabled == false

ios - Size Class 紧凑高度不能与 UIStackView 的轴和真实设备一起正常工作

ios - CoreTelephony - 处于飞行模式时的运营商名称

ios - 如何将数据从collectionView和tableView传递到detailViewController?

接受带有可选参数的 JSON 的 Swift 3 init 方法

ios - 在 Attributed TextView (Xcode) 中更改文本颜色

ios - 使用 NSURLConnection 时如何制作完整数据

ios - 在带有 Cocoapods 的 Swift 中使用 Evernote iOS API 在 Xcode 中找不到文件错误

javascript - 如何在 javascript 或 jquery 或其他方式中不使用 windows.open 的情况下禁用地址栏