- Home /
iOS - Saving Data (Image)
Hello,
I've been looking around to see how its possible to save data such as an image on an iOS. There seems to be many different ways which has brought confusion.
What is the best possible way to save an image, or audio on iOS? For example, lets say I have an Image Editing application that I'm building in Unity for iOS. I want to be able to save the users edited image within the app, on the iOS.
The only true way I know about saving data is PlayerPrefs, so with that, I can just convert the image into byte data, and have PlayerPrefs hold that data for me. But theres got to be a better way.
Could someone please shred some light on this topic for me please?
Thanks.
Answer by abi-kr01 · Jun 02, 2015 at 05:32 PM
You Can see i have done it for ios and android
or use it like this .first convert your image into bytes and then
IEnumerator save_png_player()
{
if (Application.platform == RuntimePlatform.Android)
{
File.WriteAllBytes( Application.persistentDataPath+"/" +name+".jpg",bytes );
}
else
{
File.WriteAllBytes( Application.dataPath+"/Resources/save_screen/"+name+".jpg",bytes );
}
yield return null;
}
for audio i have this, work on both ios and droid record it and play it [link text][2]
Thanks for this, I tried your save/load script on the link you supplied, and it doesn't work. The save seems to work okay, but the load doesn't:
When I try and load, I get this error:
UnauthorizedAccessException: Access to the path "/private/var/mobile/Containers/Bundle/Application/17484CC4----**/app_name.app/Data/Resources/image_save.png" is denied.
There really doesn't seem to be an easy way to save and load files on iOS, which amazes me!...?
have you resolve this issue? since I am looking for the solution for the same problem: how to transfer image from gallery to texture in App, and save it in App for next time use.
update url with new as you already saved data in persistentDataPath
url=Application.persistentDataPath+"/"+tiger+".jpg";
or
url=Application.persistentDataPath+"/"+tiger";
after load it is available in "tex" variable
Your answer
Follow this Question
Related Questions
How do you copy PersistentDataFolder between devices? 2 Answers
How do I save and retrieve ordered data? Can I do this with an array? 1 Answer
Loading a list into unity 0 Answers
How can I make this script save and or load what I do in my game?? 2 Answers
XmlException when trying to read/write XML from iOS device 1 Answer