xcode NSPhotoLibraryAddUsageDescription 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46601885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NSPhotoLibraryAddUsageDescription error
提问by Mansa
I hope someone can help here. I have this Xcode / Unity project, and every time I try to build it I get this error:
我希望有人能在这里提供帮助。我有这个 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 必须包含一个 NSPhotoLibraryAddUsageDescription 键和一个字符串值,向用户解释应用程序如何使用这些数据。
I understand that in my info.plist I need a description for use of camera, library etc, but as far as I can see, I have that?
我知道在我的 info.plist 中我需要使用相机、图书馆等的描述,但据我所知,我有吗?
Here is my 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>[email protected]</string>
<string>[email protected]</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:[email protected]/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>
As you can see, i do have the descriptions in there?!?!
如您所见,我确实在那里有描述?!?!
When viewing the info.plist inside Xcode it looks like this
在 Xcode 中查看 info.plist 时,它看起来像这样
really hope that someone can help me in this matter, and thanks in advance :-)
真的希望有人能在这件事上帮助我,并提前致谢:-)
回答by iOS
You need to add below code in info.plist
您需要在 info.plist 中添加以下代码
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Here write description why you accessing photo library</string>
Privacy - Photo Library Usage Description is for read and write libraries, NSPhotoLibraryAddUsageDescription is only for read. If your app needs only read add NSPhotoLibraryAddUsageDescription
隐私 - 照片库使用说明用于读取和写入库,NSPhotoLibraryAddUsageDescription 仅用于读取。如果您的应用程序只需要读取添加 NSPhotoLibraryAddUsageDescription
For more details see this link, https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW73
See the below screenshots:
请参阅以下屏幕截图:
1) Right click on Info.plist file
1) 右键单击 Info.plist 文件
--> Select Open As option
--> 选择打开为选项
--> Click Source Code
--> 点击源代码
2) Now copy and paste above code here.
2)现在将上面的代码复制并粘贴到此处。
回答by iPatel
You need to add NSPhotoLibraryAddUsageDescription
in info.plist
file in iOS 11.
您需要添加NSPhotoLibraryAddUsageDescription
在info.plist
文件中的iOS 11。
If you want to add photo/image in your photo library then you must add this key to info.plist file
如果要在照片库中添加照片/图像,则必须将此密钥添加到 info.plist 文件中
回答by Simon Anthony
I have found that you also need to add
我发现你还需要添加
<key>NSCameraUsageDescription</key>
<string>Photo Library Access Warning</string>
or it will still crash. You need all three at the moment - March 2018
否则它仍然会崩溃。您目前需要所有三个 - 2018 年 3 月