[英]Request Location Swift iOS 9
我试图让我的应用程序请求用户在使用该应用程序时允许位置服务,
我已经在ViewController.swift
导入了以下内容
import CoreData
import Foundation
import CoreLocation
并且在我的ViewController.swift
也有以下代码
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let manager = CLLocationManager()
if CLLocationManager.locationServicesEnabled() {
manager.startUpdatingLocation()
}
if CLLocationManager.authorizationStatus() == .NotDetermined {
manager.requestWhenInUseAuthorization()
}
此外,在进行了大量研究之后,我发现我必须在info.plist
添加以下内容
<key>NSLocationUsageDescription</key>
<string>AppName needs to use your location to help you find other blah blah blah near you</string>
尽管在模拟器中运行应用程序时采取了这些步骤,但在使用应用程序时没有收到请求访问的提示
在您的Info.plist
中的key
下方插入
NSLocationWhenInUseUsageDescription
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.