- Home /
Can unity read file in iOS folder?
hi all, I am trying read file in iOS folder but it failed.
in xcode , i let my ipad to download file and save it
like this
//download in xcode
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSArray *pathLis = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [pathLis objectAtIndex:0];
path = [path stringByAppendingPathComponent: @"aaa.unity3D"];
if([tempData writeToFile:path atomically:NO])
{
NSLog(@"YES");
}
else
{
NSLog(@"NO");
}
NSLog(@"save as %@", path);
//[tempData release];
//tempData = nil;
}
this works fine , download is ok , saving file is ok,too. but when i want to load the file in unity. it failed.
in unity i try this command
Resources.LoadAssetAtPath( Application.persistentDataPath+"/aaa.unity3D");
or WWW bundle = new WWW(file://+Application.persistentDataPath+"/aaa.unity3D"); etc..
i try any path i find in web
and i sure the path is right.
because this works great in uinty
FileStream fs = new FileStream(Application.persistentDataPath+"/aaa.unity3D", FileMode.Open, FileAccess.Read);
why?
the FileStream is byte[]
i don't know how to change to prefab or other type i wnat to use in unity.
C# "filestream" can read the file in iOS
but "Resources.LoadAssetAtPath" fail
and the path is 100% same
Anyone know about this?
or how can i change byte[] to unity object?
Sorry for my bad english~
Answer by Graham-Dunnett · Apr 11, 2012 at 10:35 AM
Resources.LoadAssetAtPath is documented as being useful in the Editor only, and the path name you give the API is a path name into the Assets folder in the Unity project.
So , i can't use Resourcesload to read file in iOS folder . but what about the WWW? it fails ,too. is that the same reason like resourcesload? WWW useful in Editor only?
Is there other way to read iOS folder by using unity? because i don't know how to change byte[] to unity prefab or unity gameobject.
Thanks to answer me~
What file are you trying to load? Is it an asset bundle that you've created with the Unity editor previously? If so, WWW.assetBundle should work if you have things set up right. Are you getting any particular error messages?
yes , the file is assetbundle , or even jpg.
I try WWW but it is not work , error log is null , i also check the progress, but it always "0". I don't know what is wrong. And i am sure the path is right. because filestream is work by use the same path.
by the way , if i use WWW to link the webpath , the log says "badpath" . So i download the file by using xcode , and save file in the ios snadbox folder. then i use WWW to the path like this "WWW(file://+Application.persistentDataPath+"/aaa.unity3D");"
Answer by kyopolo · Apr 12, 2012 at 07:33 AM
oops , the web part is my fault , it is because the assetbundel's problem. but that question is still , when i download the file in ipad. i use WWW to read the localfile , the WWW.isdone == true; but when i want to Instantiate it , it shows the log "Failed to load asset bundlel" the file is the same in my website. Anyone know about this?
Your answer
Follow this Question
Related Questions
Why a 109kb .png file teakes 8mb in unity? 1 Answer
A node in a childnode? 1 Answer
How do I read unicode text file on IOS from resources folder? 1 Answer
Access path of stored asset 0 Answers
Best way to manage stats in a text file 2 Answers