iOS 10 个应用程序已崩溃,因为它试图访问隐私敏感数据

iOS 10 App has crashed because it attempted to access privacy-sensitive data

我是 运行 我的项目,之前运行良好,但在更新我的 xcode 之后,我的应用程序崩溃并出现此错误:

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data

iOS10

中的隐私设置

A significant change in iOS 10 is that you must declare ahead of time any access to private data or your App will crash.

Once you link with iOS 10 you must declare access to any user private data types. You do this by adding a usage key to your app’s Info.plist together with a purpose string. The list of frameworks that count as private data is a long one

Contacts, Calendar, Reminders, Photos, Bluetooth Sharing, Microphone, Camera, Location, Health, HomeKit, Media Library, Motion, CallKit, Speech Recognition, SiriKit, TV Provider.

您需要将 NSCameraUsageDescription 放入您的 plist。

喜欢

<key> NSCameraUsageDescription </key>
<string>$(PRODUCT_NAME) uses Cameras</string>

例如

查看所有使用说明here

The new Privacy settings that are required if you build your apps with the iOS 10 SDK.A “Purpose String” MUST be provided in your Info.plist file if you’re accessing any of the privacy sensitive data.

“目的字符串”只是一条消息,解释了为什么应用程序需要访问将在请求权限时向用户显示的特定服务(就像我们在 [=13 以来为位置服务所做的一样) =] 8).不提供此“目的字符串”可能会导致您的应用程序崩溃。

我通过在 info.plist

中添加以下条目在我的模拟器上解决了这个问题

我还没有在真实设备上使用相机尝试过,我认为你还必须输入以下值,

我正在使用 iOS 10.2

@Anbu 的回答有一个额外的 space 会抛出异常。 Info.plist 条目应如下所示

<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) uses camera</string>

我什至不会提示我。我插入了 SKAdNetworkItems 键和 NSUserTrackingUsageDescription 键。我还有多个 info.plist 用于本地化,所有这些我都用密钥更新了。

我运行ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in 功能,它正在崩溃。崩溃日志显示:“此应用程序已崩溃,因为它试图在没有使用说明的情况下访问隐私敏感数据。该应用程序的 Info.plist 必须包含一个 NSUserTrackingUsageDescription 键,其字符串值向用户解释该应用程序如何使用此数据。 “

但我从未收到要求跟踪权限的提示

    extension ViewController: GADFullScreenContentDelegate {
  func loadVideoAd() {
    func load(){
        let request = GADRequest()
        GADInterstitialAd.load(withAdUnitID: GoogleAdKeys.Interstitial, request: request, completionHandler: { ad, error in
            if let error = error {
                print("Failed to load interstitial ad with error: \(error.localizedDescription)")
                return
            }
            self.interstitial = ad!
            self.interstitial.fullScreenContentDelegate = self
        })
    }
    
    if #available(iOS 14, *) {
      ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
        switch status{
        case .notDetermined:
          break
        case .restricted:
          break
        case .denied:
          break
        case .authorized:
          load()
        @unknown default:
          break
        }
      })
    } else {
      // Fallback on earlier versions
      load()
    }
  }

    func playVideoAd() { 
        interstitial.present(fromRootViewController: self)
    }
}