I have an image named my-image
. Can I s开发者_如何学JAVAave this image to the application bundle? If yes, can you provide me the code or paths.
As of now, I have the following code –
NSData * imageData = UIImagePNGRepresentation(userSavedImage); //convert image into .png format.
NSFileManager * fileManager = [NSFileManager defaultManager];//create instance of NSFileManager
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it
NSString * documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory
NSString * fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",txtImageName.text]]; //add our image to the path
[fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the image
NSLog(@"image saved");
However it is saving in
/Users/tsplmac01/Library/Application Support/iPhone Simulator/4.3/Applications/BC5DE1D8-B875-44BC-AC74-04A17329F29A/.
& not in the application bundle. Please tell me how I can do it.
The app bundle is read only for the app, so it is not possible to write to it.
This is a good restriction, because it would otherwise be wiped out when the app gets updated. You may want to write to the documents directory instead.
精彩评论