Unity Android/IOS 打开图片库和相机,并加载图片

来源:互联网 发布:中国联通网络怎么样 编辑:程序博客网 时间:2024/05/03 02:09

升级 iOS 10 之后目测坑还是挺多的,记录一下吧,看看到时候会不会成为一个系列。

直入正题吧

今天在调用相册时,又特么崩了。然后看到控制台输出了以下信息:
This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.

意思就是说,你需要在 info.plist 文件添加一个 NSPhotoLibraryUsageDescription的 key,然后添加一个描述。

解决方案
1.在项目中找到info.plist文件,右键点击以 Source Code形式打开
2.添加以下键值对,这里以 PhotoLibrary 作为例子

<key>NSPhotoLibraryUsageDescription</key>    <string>此 App 需要您的同意才能读取媒体资料库</string>
目测所有需要的权限描述都会在 iOS 10 beta里面crash,不用怕,控制台会有输出的,自行添加就 OK,

<key>NSCameraUsageDescription</key>        <string>cameraDesciption</string>    <key>NSContactsUsageDescription</key>        <string>contactsDesciption</string>    <key>NSMicrophoneUsageDescription</key>        <string>microphoneDesciption</string>



文/wzbdroid(简书作者)
原文链接:http://www.jianshu.com/p/c212cde86877
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。


Unity调用IOS/Android调用原生相机以及相册的项目时,Xcode提示ARC forbids explicit message sendof 'retain'

'retain' is unavailable: not available inautomatic reference counting mode

从字面上来解释就是,arc 禁止显示发送retain消息。

    其实就是使用ARC之后,不允许直接调用retain, release, autorelease, dealloc, retainCount这些方法了,编译器会在合适的地方将这些代码添加进去,解决这样的问题只需要删除与手动管理内存相关的代码(一般就是报错的代码)即可。

解决方法:

找到"Build Settings" -> 找到"Compile Sources" -> 找到出错的类,在对应类的"Compiler Flags"中添加"-fno-objc-arc"(双击后输入)


运行后发现相框显示的内容都是英文,解决方法:打开Info.plist Localization native development region 的值en改为 China就可以了





下载地址:http://download.csdn.net/detail/he_wen_jian/9532021

如果想取消选择图片后的裁剪操作,需要进行如下修改:

IOS

把picker.allowsEditting=YES改为NO,[] UIImagePickerControllerEditedImage改为UIImagePickerControllerOriginalImage




Android待更新

下载地址:http://download.csdn.net/detail/he_wen_jian/9532021

1 0