4
一個應用程序我正在開發在Objective-C的iPhone應用程序的資源文件夾中的文件。我的問題是,我的應用程序必須保存從網址獲取的圖像。我認爲該文件夾是隻讀的。這是我的代碼保存圖像:如何保存在Objective-C
-(void)banner:(NSString *)path{
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: path]];
UIImage *image = [UIImage imageWithData: imageData];
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
NSString* pathEnd = [resourcePath stringByAppendingFormat:@"/banner.png"];
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
NSError *writeError = nil;
[data1 writeToFile:pathEnd options:NSDataWritingAtomic error:&writeError];
}
但是當我找回圖像,它不是文件夾中。我能做什麼?
感謝您!我會試試:) scuse我要第一個代碼,我嘗試了一些解決方案:) – JackTurky
它爲我工作,爲什麼你說:「你不能,該應用程序包是隻讀的。」 –
@ArashZeinoddini它可以在模擬器和越獄設備上工作。但是在普通的iOS設備上,應用程序捆綁包是隻讀的。 – rckoenes