ios - NSPhotoLibraryAddUsageDescription 错误

标签 ios xcode cocoa-touch camera plist

我希望有人能在这里提供帮助。我有这个 Xcode/Unity 项目,每次我尝试构建它时都会收到此错误:

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

我知道在我的 info.plist 中我需要使用相机、图书馆等的描述,但据我所知,我有吗?

这是我的 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>CFBundleDisplayName</key>
    <string>MyGame</string>
    <key>CFBundleExecutable</key>
    <string>${EXECUTABLE_NAME}</string>
    <key>CFBundleIconFiles</key>
    <array>
      <string>AppIcon57x57.png</string>
      <string>AppIcon57x57@2x.png</string>
      <string>AppIcon60x60@2x.png</string>
      <string>AppIcon72x72@2x~ipad.png</string>
      <string>AppIcon72x72~ipad.png</string>
      <string>AppIcon76x76@2x~ipad.png</string>
      <string>AppIcon76x76~ipad.png</string>
    </array>
    <key>CFBundleIdentifier</key>
    <string>com.mycompany.${PRODUCT_NAME}</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.3</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSRequiresIPhoneOS</key>
    <true />
    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSAllowsArbitraryLoads</key>
      <true />
    </dict>
    <key>UIApplicationExitsOnSuspend</key>
    <false />
    <key>UILaunchStoryboardName~ipad</key>
    <string>LaunchScreen-iPad</string>
    <key>UILaunchStoryboardName~iphone</key>
    <string>LaunchScreen-iPhone</string>
    <key>UILaunchStoryboardName~ipod</key>
    <string>LaunchScreen-iPhone</string>
    <key>UIPrerenderedIcon</key>
    <false />
    <key>UIRequiredDeviceCapabilities</key>
    <array>
      <string>armv7</string>
    </array>
    <key>UIRequiresFullScreen</key>
    <true />
    <key>UIRequiresPersistentWiFi</key>
    <false />
    <key>UIStatusBarHidden</key>
    <true />
    <key>UIStatusBarStyle</key>
    <string>UIStatusBarStyleDefault</string>
    <key>UISupportedInterfaceOrientations</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>Unity_LoadingActivityIndicatorStyle</key>
    <integer>-1</integer>
    <key>UnityCloudProjectID</key>
    <string>xxx-xxx-xxx-xxx-xxx</string>
    <key>UnityCrashSubmissionURL</key>
    <string>https://a:b@perf-events.cloud.unity3d.com/symbolicate</string>
    <key>NSCameraUsageDescription</key>
    <string>Used for profile image</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>Used for profile image</string>
    <key>FacebookAppID</key>
    <string>xxxxx</string>
    <key>CFBundleURLTypes</key>
    <array>
      <dict>
        <key>CFBundleURLName</key>
        <string>facebook-unity-sdk</string>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>xxxxx</string>
        </array>
      </dict>
    </array>
    <key>LSApplicationQueriesSchemes</key>
    <array>
      <string>fbapi</string>
      <string>fb-messenger-api</string>
      <string>fbauth2</string>
      <string>fbshareextension</string>
    </array>
  </dict>
</plist>

如你所见,我确实有描述?!?!

在 Xcode 中查看 info.plist 时,它看起来像这样

enter image description here

真的希望有人能在这件事上帮助我,在此先感谢:-)

最佳答案

需要在info.plist中添加如下代码

<key>NSPhotoLibraryAddUsageDescription</key>
<string>Here write description why you accessing photo library</string>

Privacy - Photo Library Usage Description 适用于读写库, NSPhotoLibraryAddUsageDescription 仅供阅读。如果你的应用只需要读取添加 NSPhotoLibraryAddUsageDescription

有关详细信息,请参阅此链接,https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW73

请看下面的截图:

1) 右键点击Info.plist文件

-->选择打开方式选项

-->点击源代码

enter image description here

2) 现在将上面的代码复制并粘贴到这里

enter image description here

关于ios - NSPhotoLibraryAddUsageDescription 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46601885/

相关文章:

ios - 'isMenuVisible' 的 Setter 在 iOS 13.0 中被弃用

ios - 为什么在使用蜂窝网络后下载不会切换回 wifi?

ios - 删除 UIPageViewController 中的循环 AVPlayer Observer

iOS 键盘颜色更改 - keyboardAppearance 深色不粘

iphone - Xcode 的“构建和存档”命令在哪里寻找其 iTunes 图稿?

iphone - 连接到 iOS 4 上的 MobileMusicPlayer

ios - 带有 allowsEditing 的 UIImagePickerController 不允许平移裁剪

ios - 在 Xcode 的调试控制台输出中禁用自动布局约束错误消息

ios - 我可以在我的 iOS 应用程序中使用实验性 WebKit 功能吗?

ios - 如何在 aps-environment 设置为 "production"的情况下运行我的 iOS 应用程序 (Xcode 6)?