我有一张名为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/.
&安培;不在应用程序包中。请告诉我如何做到这一点。
答案 0 :(得分:5)
app app仅对应用程序是只读的,因此无法写入。
这是一个很好的限制,因为它会在应用程序更新时被删除。您可能希望写入文档目录。