-2

我有一个名为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");

但是它正在节省

/Users/tsplmac01/Library/Application Support/iPhone Simulator/4.3/Applications/BC5DE1D8-B875-44BC-AC74-04A17329F29A/.

& 不在应用程序包中。请告诉我我该怎么做。

4

1 回答 1

5

应用程序包对该应用程序是只读的,因此无法对其进行写入。

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

于 2011-06-26T11:56:47.410 回答