简体   繁体   English

在调试器中出现错误:此应用试图在没有使用说明的情况下访问隐私敏感数据

[英]Getting error in debugger: This app has attempted to access privacy-sensitive data without a usage description

I'm having an issue in the debug area.我在调试区域遇到问题。 It's saying that: " This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain both “NSLocationAlwaysAndWhenInUseUsageDescription” and “NSLocationWhenInUseUsageDescription” keys with string values explaining to the user how the app uses this data. "它是说:“这个应用程序试图在没有使用说明的情况下访问隐私敏感数据。该应用程序的 Info.plist 必须同时包含“NSLocationAlwaysAndWhenInUseUsageDescription”和“NSLocationWhenInUseUsageDescription”键以及向用户解释应用程序如何使用此数据的字符串值。

The app I'm creating involves obtaining the user's location only when s/he is using the app, or in other words, only in the foreground.我正在创建的应用程序涉及仅在他/她正在使用该应用程序时获取用户的位置,或者换句话说,仅在前台。 I've only added in my info.plist: Key(Privacy - Location When In Use Usage Description), Type(String), Value(We'll use your location to find jobs near you.).我只在我的 info.plist 中添加了:Key(Privacy - Location When In Use Usage Description), Type(String), Value(We'll use your location to find jobs near you.)。

Here is the code in my view controller:这是我认为 controller 中的代码:

import UIKit
import Foundation
import CoreLocation

class JobTableViewController: UITableViewController, CLLocationManagerDelegate {
    
let locationManager = CLLocationManager()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    
// Implement Indeed Job Search API
    let headers = [
        "x-rapidapi-host": "indeed-indeed.p.rapidapi.com",
        "x-rapidapi-key": "838897ae8cmsha8fef9af0ee840dp1be982jsnf48d2de3c84a"
    ]

    let request = NSMutableURLRequest(url: NSURL(string: "https://indeed-indeed.p.rapidapi.com/apigetjobs?v=2&format=json")! as URL,
                                            cachePolicy: .useProtocolCachePolicy,
                                        timeoutInterval: 10.0)
    request.httpMethod = "GET"
    request.allHTTPHeaderFields = headers

    let session = URLSession.shared
    let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
        if (error != nil) {
            print(error!)
        } else {
            let httpResponse = response as? HTTPURLResponse
            print(httpResponse!)
        }
    })

    dataTask.resume()
   
    
// Recieve live location from user
    // For use when the app is open
    locationManager.requestWhenInUseAuthorization()
    
    if CLLocationManager.locationServicesEnabled() {
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.startUpdatingLocation()
    }
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    if let location = locations.first {
        print(location.coordinate)
    }
}

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
    if(status == CLAuthorizationStatus.denied) {
        showLocationDisabledPopUp()
        
    }
}

// If user disabled location services
func showLocationDisabledPopUp() {
    let alertController = UIAlertController(title: "Location Access is Disabled", message: "In order to automatically find jobs near you, we need your location.", preferredStyle: .alert)
    
    let cancelAction = UIAlertAction(title: "Okay", style: .cancel, handler: nil)
    alertController.addAction(cancelAction)
    
    let openAction = UIAlertAction(title: "Open Settings", style: .default) { (action) in
        if let url = URL(string: UIApplication.openSettingsURLString) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
    }
    alertController.addAction(openAction)
    
    self.present(alertController, animated: true, completion: nil)
    
}

I am able to successfully build the app and log in to the app.我能够成功构建应用程序并登录到应用程序。 The debugger even successfully shows the coordinates of the simulator.调试器甚至成功地显示了模拟器的坐标。 However, it still gives me this warning and I am unable to use the coordinates to find nearby jobs through the API that I installed (which the code is also included above).但是,它仍然给我这个警告,我无法使用坐标通过我安装的 API 找到附近的工作(上面也包含代码)。 I don't know why it's even warning me about "NSLocationAlwaysAndWhenInUseUsageDescription" since it's not mentioned once in my program.我不知道为什么它甚至警告我有关“NSLocationAlwaysAndWhenInUseUsageDescription”的信息,因为它在我的程序中一次也没有提到。

Is there a legit reason for this warning?此警告是否有正当理由? Also, is this warning connected to the fact that the app is unable to provide nearby jobs via the API?此外,此警告是否与应用程序无法通过 API 提供附近的工作这一事实有关? I know that this is all very confusing, so I've attached screenshots of everything below.我知道这一切都很混乱,所以我在下面附上了所有内容的截图。 Please ask any questions for clarification and thanks so much for all of your help!请提出任何问题以进行澄清,非常感谢您的所有帮助!

info.plist screenshot debugger screenshot info.plist 截图调试器截图

The debugger message and the other two answers tell you what you need to do.调试器消息和其他两个答案告诉您需要做什么。 Add the additional usage key with the same text.添加具有相同文本的附加使用密钥。

Why?为什么? This is required because as of iOS 12 a user can respond "when in use" when asked for "always" and in iOS 13 will only get asked for "when in use" when an app first asks for "always".这是必需的,因为从 iOS 12 开始,用户可以在要求“始终”时响应“使用时”,而在 iOS 13 中,只有在应用程序首次要求“始终”时才会被要求“使用时”。

Prior to iOS 12, the different "when in use" and "always" permission request strings are used depending on what your app asks for.在 iOS 12 之前,根据您的应用程序要求使用不同的“使用时”和“始终”权限请求字符串。

In iOS 12 and later you need to have a usage string that make sense in both an "always" and "when in use" scenario in a single key.在 iOS 12 及更高版本中,您需要在单个键中的“始终”和“使用时”场景中都有一个使用字符串。

Apple provides the new NSLocationAlwaysAndWhenInUseUsageDescription Key to allow app developers an opportunity to provide different information in light of the new behaviour. Apple 提供了新的NSLocationAlwaysAndWhenInUseUsageDescription键,让应用程序开发人员有机会根据新行为提供不同的信息。

In theory this is the only key that is required after iOS 12, but for backward compatibility you are required to include both the old and new keys, even if your minimum ios target is iOS 12 or later.理论上,这是 iOS 12 之后唯一需要的密钥,但为了向后兼容,您需要同时包含旧密钥和新密钥,即使您的最小 ios 目标是 Z1BDF605991920DB11CBDF128508204C4EBZ 或更高版本。

Just add both the keys NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription inside info.plist, locations services will start completely fine.只需在 info.plist 中添加NSLocationAlwaysAndWhenInUseUsageDescriptionNSLocationWhenInUseUsageDescription这两个键,位置服务将完全正常启动。

For fetching location updates from the user's device you need to ask for the user's permission.要从用户的设备获取位置更新,您需要征得用户的许可。 If not asked, Apple will reject the app when the app is submitted for review.如果未要求,Apple 将在应用程序提交审核时拒绝该应用程序。

Add these two keys in info.plist -在 info.plist 中添加这两个键 -

NSLocationWhenInUseUsageDescription
name - Privacy - Location When In Use Usage Description
reason - why your app wants to access location
NSLocationAlwaysAndWhenInUseUsageDescription
name - Privacy - Location Always and When In Use Usage Description
reason - why your app wants to access location

In my case is forget set Privacy - Location When In Use Usage Description in Info.plist在我的例子中是忘记设置Privacy - Location When In Use Usage Description

在此处输入图像描述

You might have forgot to add Privacy - Location When In Use Usage Description in info.plist.您可能忘记在 info.plist 中添加Privacy - Location When In Use Usage Description

In order to do that, just head to info.plist and click on the + button and paste Privacy - Location When In Use Usage Description .为此,只需前往 info.plist 并单击+ 按钮并粘贴Privacy - Location When In Use Usage Description

Don't forget to add a comment to let users understand why you're asking for their position.不要忘记添加评论,让用户了解您为什么要求他们提供 position。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 此应用已崩溃,因为它尝试访问没有使用说明的隐私敏感数据,即使使用使用说明也是如此 - This app has crashed because it attempted to access privacy-sensitive data without a usage description, even with usage description xctest 此应用程序试图在没有使用说明的情况下访问隐私敏感数据 - xctest This app has attempted to access privacy-sensitive data without a usage description Phonegap应用程序NSCalendarsUsageDescription错误:此应用程序尝试访问对隐私敏感的数据,而没有使用说明 - Phonegap app NSCalendarsUsageDescription error:This app attempts to access privacy-sensitive data without a usage description 该应用已崩溃,因为它试图访问对隐私敏感的数据 - This app has crashed because it attempted to access privacy-sensitive data iOS10应用程序已崩溃,因为它尝试访问对隐私敏感的数据 - iOS10 app has crashed because it attempted to access privacy-sensitive data 由于 GoogleSignIn 和 AdMob,iOS 10 GM 在提交应用程序时出现“应用程序尝试访问没有使用说明的隐私敏感数据”的发布错误 - iOS 10 GM release error when submitting apps "app attempts to access privacy-sensitive data without a usage description" due to GoogleSignIn, AdMob iOS 10 应用程序崩溃,因为它试图访问隐私敏感数据 - iOS 10 App has crashed because it attempted to access privacy-sensitive data iOS - 应用程序崩溃,因为它试图在没有使用说明的情况下访问隐私敏感数据 - iOS - App crashed because it attempted to access privacy - sensitive data without a usage description 应用程序被拒绝:查找(cocoapod)库访问隐私敏感数据的系统方法 - App rejected: Systematic way to find (cocoapod) library that accesses privacy-sensitive data 如何使UITests-Runner能够访问隐私敏感数据 - How to make UITests-Runner able to access privacy-sensitive data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM