How to load image in a directory different than NSBundle?
SUPER HARD QUESTION
Here is my projet:
I use 3000 jpegs in an iPhone Project. In a normal situation, the 3000 files are loaded in the 'NSBundle' (encapsulated with the App) and then load on the iPhone. The problem is the app is around 500 Mo.
So i'd like to copy the images in a different directory ('Documents' for example) than the bundle AND then REMOVE all the jpegs from the bundle. My idea is that after the first launch of the app, the app will be only 2Mo and the next launches will be very fast.
My first idea was :
file in Bundle: the path of the file in the Bundle file Destination : the path of where i want to put the file
if([manager copyItemAtPath:fileInBundle toPath:fileDestination error:&error]) if([manager removeItemAtPath:fileInBundle error:&error])
Of course I tried 'moveItemToPath' ^^
The copy works fine if you copy outside 'NSBundle' but the remove is impossible :
NSFilePath = "/var/mobile/Applications/4A173D2E-5CFC-4D12-978C-68CF5C0ED352/myLovelyApp.app/Main.jpg"; NSUnderlyingError = Error Domain=NSPOSIXErrorDomain Code=1 "Operation could not be completed. Operation not permitted";
Obviously, i check if main.jpg exist by a '[manager fileExistsAtPath:fileInBundle]' and i check the deletable possibility by : '[manager isDeletableFileAtPath:fileInBundle]' (NO !)
So after, I check the POSIX Permission attributes of the file and the Directory : NSDictionary* whatPermissions=[manager attributesOfItemAtPath:fileInBundle error:&error]; NSLog(@"File POSiX Permission : %@",[whatPermissions objectForKey:@"NSFilePosixPermissions"]);
I get a 493 --> Chmod 755 -> read-Write-Exe/read-Exe/read-Exe. So impossible to remove or write file in that NSBundle.
I tried to force by switching the Attribute POSIX PERMISSION : [manager setAttributes:permission ofItemAtPath:fileInBundle error:&error] // put the posix permission to 511 (chmod 777)
But it did'nt work.
Second idea: So Xcode Building Setting was maybe my solution with the INSTALL PERMISSION flag : 'u+w,go-w,a+rX'
but I tried a lot of possibility and nothing is working (maybe I didn't find the good one) i Tried : 'u+rwx,go+rwx,a+rwx', 'u+rw,go-rw,a+rwX'...
But nothing happened I found the 'ALTERNATE_PERMISSIONS_FILES' with 'ALTERNATE_MODE', but it seem's I have to fill the list with my 3000 jpg one by one in the xcode params. And when i tried with just 10 files. It didn't work. I must say that I never find any tutorial or blog post on that subjects. So if you know one of it. please feel free to share.
In the XCode Build System Guide, There is NO HELP!!!!
I tried to change the target destination: I add a Copy File phase in the target system. And then put all the image inside but it seem's that it has no effect, and the file are not loaded on the iPhone.
HOW CAN I PUT DIRECTLY THE 3000 IMAGE FILES IN A DIRECTORY AND THEN DELETE IT.
Here is how the iPhone directories looks like :
"private/var/mobile/Applications/4A173D2E-5CFC-4D12-978C-68CG5C0ED245/myLovelyApp.app/number7_S.png", "private/var/mobile/Applications/4A173D2E-5CFC-4D12-978C-68CG5C0ED245/myLovelyApp.app/number8_N.png", "private/var/mobile/Applications/4A173D2E-5CFC-4D12-978C-68CG5C0ED245/myLovelyApp.app/number8_S.png", "private/var/mobile/Applications/4A173D2E-5CFC-4D12-978C-68CG5C0ED245/myLovelyApp.app/number9_N.png", "private/var/mobile/Applications/4A173D2E-5CFC-4D12-978C-68CG5C0ED245/myLovelyApp.app/number9_S.png", "private/var/mobile/Applications/4A173D2E-5CFC-4D12-978C-68CG5C0ED245/Documents", "private/var/mobile/Applications/4A173D2E-5CFC-4D12-978C-68CG5C0ED245/Library", "private/var/mobile/Applications/4A173D2E-5CFC-4D12-978C-68CG5C0ED245/Library/Caches", "private/var/mobile/Applications/4A173D2E-5CFC-4D12-978C-68CG5C0ED245/Library/Preferences", "private/var/mobile/Applications/4A173D2E-5CFC-4D12-978C-68CG5C0ED245/Library/Preferences/.GlobalPreferences.plist", "private/var/mobile/Applications/4A173D2E-5CFC-4D12-978C-68CG5C0ED245/Library/Preferences/com.apple.PeoplePicker.plist", "private/var/mobile/Applications/4A173D2E-5CFC-4D12-978C-68CG5C0ED245/tmp",
I would like to move file from NSBundle to Documents directory.
THANK FOR YOUR HELP
Your NSBundle should NEVER be modified at runtime, as the application is code-signed by Apple. If you edit the bundle, you risk the app crashing:
This is the bundle directory containing the application itself. Because an application must be signed, you must not make changes to the contents of this directory at runtime. Doing so may prevent your application from launching later.
(Source - Table 1-1 under 'The File System')
Also, the bundle being smaller will not reduce load time - the main reason of having a smaller bundle is to make downloading off the app store quicker. What you could always do is host the images somewhere, and then download the images into the documents directory on first launch.
My idea is that after the first launch of the app, the app will be only 2Mo and the next launches will be very fast.
So is the problem that it takes a long time to build and deploy a development version of this application? Or is your problem that a production build takes to long to start on an end-user device?
The latest Xcode is really much much better with incrementally copying only changed resources. Changing one image should result in just one quick copy and certainly not all 3000 of them.