简体   繁体   English

未获得位置iOS8的授权

[英]Not getting authorization for location iOS8

I've tried looking at other solutions such as: requestWhenInUseAuthorization() not Work in iOS 8 With NSLocationWhenInUseUsageDescription Key in Info.plist 我尝试查看其他解决方案,例如: requestWhenInUseAuthorization()在iOS 8中无法使用Info.plist中的NSLocationWhenInUseUsageDescription键

But I can't get authorization prompt to get location. 但是我无法获得授权提示以获取位置。

That person's issue in that other question was that he had is manager inside his viewDidLoad , I do not, but still an authorization prompt is not showing up. 这个人在另一个问题中的问题是,他在viewDidLoad内有经理,我没有,但是仍然没有出现授权提示。 I've updated my plist: 我更新了我的清单:

gyazo.com/b66946b9976aa226a21c0bf6e3817e3a

and have my manager outside of my viewDidLoad : 并且让我的经理不在我的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

Since It's not getting auth, It's never hitting the locationManager function. 由于它没有获得身份验证,因此它从未命中过locationManager函数。

The prompt only shows if CLLocationManager.authorizationStatus() == .NotDetermined . 提示仅显示CLLocationManager.authorizationStatus() == .NotDetermined If the user previously denied access, you won't see the prompt anymore. 如果用户以前拒绝访问,则不会再看到提示。 You should check the status before self.locationManager.requestWhenInUseAuthorization() . 您应该在self.locationManager.requestWhenInUseAuthorization()之前检查状态。 If it shows anything but .NotDetermined , look at the location settings for the app and the device. 如果显示的不是.NotDetermined ,请查看应用程序和设备的位置设置。

If the status is .NotDetermined and the prompt still does not show, I would double check spelling of the NSLocationWhenInUseUsageDescription . 如果状态为.NotDetermined ,但提示仍然不显示,我将仔细检查NSLocationWhenInUseUsageDescription拼写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM