Unity Android/IOS 打開圖片庫和相機,並加載圖片

升級 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待更新


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章