gpt4 book ai didi

ios - 不允许 Xcode 位置访问

转载 作者:行者123 更新时间:2023-11-29 00:19:08 24 4
gpt4 key购买 nike

我使用 Xcode 8.2.1 和 Swift 3,在我的应用程序中有一个 map View ,用户应该能够按下按钮, map 就会放大他们的位置。

在 Info.plist 中,我添加了两行:值为“asdf”的 NSLocationAlwaysUsageDescription 和值为“fdas”的隐私 - 使用时位置使用说明。

在运行应用程序之前,我选择“模拟位置”并选择预设位置。但是,每当用户按下该按钮时, map 就会缩放到海洋中的某个随机位置,并将以下消息打印到控制台:

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,然后选择“打开方式...”,然后选择“源代码”时,我会看到以下内容:

<key>NSLocationWhenInUseUsageDescription</key>
<string>Need your location for this app!</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs your location</string>

当查看源代码时,确保您的 info.plist 包含与这些类似的条目应该可以解决您的问题。

属性列表中的等效条目将是隐私 - 使用时的位置描述隐私 - 始终使用位置描述

关于ios - 不允许 Xcode 位置访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44474365/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com