我只是用iOS 11 SDK重建了我的应用程序,试图删除blue banner现在总是出现的应用程序。我以为“很棒,那很有效”,只是发现定位服务现在根本无法正常工作。
该应用程序过去曾与iOS 10配合使用-有人听到了吗?
Answers:
看来苹果已经添加了另一个隐私功能。用户现在可以覆盖我们requestAlwaysAuthorization并将其降级为requestWhenInUseAuthorization-这意味着作为开发人员,我们现在必须在Info.plist
我发现他们已经添加了新密钥 NSLocationAlwaysAndWhenInUseUsageDescription 
/*
*      Either the NSLocationAlwaysAndWhenInUseUsageDescription key or both the
*      NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription
*      keys must be specified in your Info.plist; otherwise, this method will do
*      nothing, as your app will be assumed not to support Always authorization.
*/
但是,使用此新密钥后,位置服务仍然无法正常工作,在进一步搜索后,我发现此gem与所有其他调试信息混合在一起:
这个应用程式已尝试存取没有使用说明的隐私权敏感资料。应用程序的Info.plist必须同时包含NSLocationAlwaysAndWhenInInUseUsageDescription和NSLocationWhenInUseUsageDescription键,并带有向用户说明该应用程序如何使用此数据的字符串值
这与我在更新CLLocationManager.h文件中找到的注释直接矛盾。因此,我创建了雷达。
好消息,如果您遵循调试控制台IE的建议。同时添加新密钥NSLocationAlwaysAndWhenInUseUsageDescription和旧密钥之一NSLocationWhenInUseUsageDescription,Locations服务将再次开始工作。
NSLocationAlwaysUsageDescription我所需的权限添加到Info.plist中。但是我在控制台中收到上述消息,说我也需要添加NSLocationWhenInUseUsageDescription。
                    startUpdatingLocation还是requestLocation?
                    startUpdatingLocation
                    只是添加解决此问题的步骤:
2种方法:
A)简单方法:选择Info.plist文件,添加属性,请注意,它们以PRIVCY而不是LOCATION开头...因此,这些变量的确切名称以“ Privacy-Location ...”开头,等等,添加每个都在这里,并描述用户将如何在警告中看到这一点。
B)硬/有趣/编程方式(我更喜欢这种方式):
右键点击您应用的Info.plist,然后选择“查看源代码”,您应该以XML格式查看所有内容,
遵循其他......格式,并如下添加这些属性:
<key>NSLocationAlwaysUsageDescription</key>
<string>Program requires GPS to track cars and job orders</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Program requires GPS to track cars and job orders</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Program requires GPS to track cars and job orders</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app uses your Microphone to allow Voice over IP communication with the Program Admin system</string>
保存,然后在info.plist文件上单击鼠标右键,然后选择“属性列表”,这将使该文件重新回到默认视图。
编辑:
另一个成员要求输入代码,这里是:
1)在您的.H文件中,添加:
@property (strong, nonatomic) CLLocationManager *LocationManager;
2)在您的.M文件上,在ViewDidAppear()函数下添加:
_LocationManager = [[CLLocationManager alloc] init];
[_LocationManager setDelegate:self];
_LocationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
_LocationManager.pausesLocationUpdatesAutomatically = NO;
[_LocationManager requestAlwaysAuthorization];
_LocationManager.headingFilter = 5;
_LocationManager.distanceFilter = 0;
[_LocationManager startUpdatingLocation];
[_LocationManager startUpdatingHeading];
这对我来说很好,希望代码也对您有用。
问候
海德
viewwillAppear 并在中删除委托viewwilldisapper。如果我去设置并选择已经选择的Allow Always。我只得到一次更新,然后就没有了。想法如何解决。提前致谢!!
                    在Swift 4.0.3中工作
   <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
   <string>Description</string>
   <key>NSLocationAlwaysUsageDescription</key>
   <string>Will you allow this app to always know your location?</string>
   <key>NSLocationWhenInUseUsageDescription</key>
   <string>Do you allow this app to know your current location?</string>  
    我遇到了一个需要“始终授权”的应用程序,并通过以下步骤解决了该问题:
1. 将 NSLocationWhenInUseUsageDescription密钥添加到Info.plist
2. 添加 NSLocationAlwaysAndWhenInUseUsageDescription到Info.plist
3. 添加 NSLocationAlwaysUsageDescription到Info.plist(以支持<iOS 11)
4. 致电 requestWhenInUseAuthorization() 之前 requestAlwaysAuthorization()
您不能在requestWhenInUseAuthorization()之前执行requestAlwaysAuthorization()。您必须升级到该权限级别。完成这些更改后,位置更新将再次开始正常工作。
更多详情可在这找到:
安全胜于遗憾.. 在iOS 11中:添加以下内容,您就很好。
<key>NSLocationWhenInUseUsageDescription</key>
<string>Description</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Description</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Description</string>
    在iOS 12.2上使用Swift 5测试
步骤1.您必须在plist文件中添加以下隐私权限
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Application requires user’s location for better user experience.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Application requires user’s location for better user experience.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Application requires user’s location for better user experience.</string>
第2步。确保您具有以下快速代码以获取当前位置
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
    // MARK: Variables declearations
    @IBOutlet weak var mapView: MKMapView!
    var locationManager: CLLocationManager!
    // MARK: View Controller life cycle methods
    override func viewDidLoad() {
        super.viewDidLoad()
        //TODO: Make user you must add following three privacy permissions in plist
        //NSLocationWhenInUseUsageDescription
        //NSLocationAlwaysAndWhenInUseUsageDescription
        //NSLocationAlwaysUsageDescription
        getCurrentLocation()
    }
    func getCurrentLocation()
    {
        if (CLLocationManager.locationServicesEnabled())
        {
            locationManager = CLLocationManager()
            locationManager.delegate = self
            locationManager.desiredAccuracy = kCLLocationAccuracyBest
            locationManager.requestAlwaysAuthorization()
            locationManager.startUpdatingLocation()
        }
    }
    // MARK: Location Manager Delegate methods
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
    {
        let locationsObj = locations.last! as CLLocation
        print("Current location lat-long is = \(locationsObj.coordinate.latitude) \(locationsObj.coordinate.longitude)")
        showOnMap(location: locationsObj)
    }
    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        print("Get Location failed")
    }
    func showOnMap(location: CLLocation )
    {
        let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
        let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
        mapView.setRegion(region, animated: true)
    }
}
    斯威夫特:3 我也遇到过同样的问题。我完全搞砸了寻找解决方案。这是我解决问题的方法。
步骤1:项目文件>功能>后台模式>选择位置更新
步骤2: 将NSLocationWhenInUseUsageDescription,NSLocationAlwaysAndWhenInUseUsageDescription键添加到Info.plist
第三步:
manager.pausesLocationUpdatesAutomatically = false
manager.allowsBackgroundLocationUpdates = true