如何将文件保存到appbundle中

Chr*_*ina -2 iphone cocoa-touch objective-c app-bundle

我有一个名为的图像my-image.我可以将此图像保存到应用程序包吗?如果是,您可以向我提供代码或路径吗?

截至目前,我有以下代码 -

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");
Run Code Online (Sandbox Code Playgroud)

但它节省了

/Users/tsplmac01/Library/Application Support/iPhone Simulator/4.3/Applications/BC5DE1D8-B875-44BC-AC74-04A17329F29A/.
Run Code Online (Sandbox Code Playgroud)

而不是在应用程序包中.请告诉我如何做到这一点.

小智 5

应用包对应用程序是只读的,因此无法写入.

这是一个很好的限制,因为它会在应用程序更新时被消除.您可能希望写入文档目录.