繁体   English   中英

请求位置Swift iOS 9

[英]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.

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