Xcode 不允许访问位置信息
Xcode Location access not allowed
我正在使用 Xcode 8.2.1 和 Swift 3,在我的应用程序中有一个地图视图,用户应该可以在其中按下一个按钮,地图将放大他们的位置。
在 Info.plist 中,我添加了两行:NSLocationAlwaysUsageDescription 的值为 "asdf" 和 Privacy - Location When In Use Usage Description 的值为 "fdas".
在运行应用程序之前,我选择"Simulate Location"并选择一个预设位置。然而,每当用户按下按钮时,地图就会缩放到海洋中的某个随机位置,并且以下消息会打印到控制台:
The app's Info.plist must contain an NSLocationAlwaysUsageDescription
key with a string value explaining to the user how the app uses this
data
这是我的全部 info.plist 源代码:
`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>Need your location </key>
<string>asdf</string>
<key>Need your location</key>
<string>fdas</string>
</dict>
</plist>`
还有这个函数:
> func zoomOnLocation(sender: UIBarButtonItem) {
print("zoomOnLocation running")
/* Tracks user location */
var locationManager = CLLocationManager()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
mapView.showsUserLocation = true
if (CLLocationManager.locationServicesEnabled()) { //Check for Location Services
locationManager = CLLocationManager()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
//Zoom to user location
let noLocation = CLLocationCoordinate2D()
let viewRegion = MKCoordinateRegionMakeWithDistance(noLocation, 200, 200)
mapView.setRegion(viewRegion, animated: false)
DispatchQueue.main.async {
locationManager.startUpdatingLocation()
}
}
非常感谢任何帮助!
听起来你在 info.plist 中混用了语法。您说您添加的其中一个条目写为 属性 列表 属性,另一个作为来源。当我在使用定位服务的应用程序中右键单击 info.plist,然后 select Open As... 然后 Source Code 我看到了这些:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Need your location for this app!</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs your location</string>
确保您的 info.plist 包含与这些类似的条目,当被视为 源代码 应该可以解决您的问题。
属性 列表中的等效项是 隐私 - 使用时的位置描述 和 隐私 - 位置始终使用描述.
我正在使用 Xcode 8.2.1 和 Swift 3,在我的应用程序中有一个地图视图,用户应该可以在其中按下一个按钮,地图将放大他们的位置。
在 Info.plist 中,我添加了两行:NSLocationAlwaysUsageDescription 的值为 "asdf" 和 Privacy - Location When In Use Usage Description 的值为 "fdas".
在运行应用程序之前,我选择"Simulate Location"并选择一个预设位置。然而,每当用户按下按钮时,地图就会缩放到海洋中的某个随机位置,并且以下消息会打印到控制台:
The app's Info.plist must contain an NSLocationAlwaysUsageDescription key with a string value explaining to the user how the app uses this data
这是我的全部 info.plist 源代码:
`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>Need your location </key>
<string>asdf</string>
<key>Need your location</key>
<string>fdas</string>
</dict>
</plist>`
还有这个函数:
> func zoomOnLocation(sender: UIBarButtonItem) {
print("zoomOnLocation running")
/* Tracks user location */
var locationManager = CLLocationManager()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
mapView.showsUserLocation = true
if (CLLocationManager.locationServicesEnabled()) { //Check for Location Services
locationManager = CLLocationManager()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
//Zoom to user location
let noLocation = CLLocationCoordinate2D()
let viewRegion = MKCoordinateRegionMakeWithDistance(noLocation, 200, 200)
mapView.setRegion(viewRegion, animated: false)
DispatchQueue.main.async {
locationManager.startUpdatingLocation()
}
}
非常感谢任何帮助!
听起来你在 info.plist 中混用了语法。您说您添加的其中一个条目写为 属性 列表 属性,另一个作为来源。当我在使用定位服务的应用程序中右键单击 info.plist,然后 select Open As... 然后 Source Code 我看到了这些:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Need your location for this app!</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs your location</string>
确保您的 info.plist 包含与这些类似的条目,当被视为 源代码 应该可以解决您的问题。
属性 列表中的等效项是 隐私 - 使用时的位置描述 和 隐私 - 位置始终使用描述.