-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/.
&不保存在應用程序包。請告訴我如何做到這一點。
嘿夏爾曼,你甚至考慮過尋找它嗎? – vikingosegundo
[寫入應用程序包中的文件時出現問題]的可能重複(http://stackoverflow.com/questions/3564153/problem-in-writing-to-a-file-in-application-bundle) – vikingosegundo