我已經實現了將文件寫入文檔目錄的邏輯。現在如何解決文件寫入問題到文件目錄?
NSData *pngData = UIImagePNGRepresentation([UIImage imageNamed:@"logo_icon_login.png"]);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"image.png"];
if ([[NSFileManager defaultManager] isWritableFileAtPath:filePath])
{
[pngData writeToFile:filePath atomically:YES];
}
else
{
NSLog(@"Not writable.");
}
問題是在一些設備它說:不可寫。在文檔目錄中寫入文件之前,我是否需要任何權限?
參閱本:http://stackoverflow.com/questions/11053842/how-to-save-file-in-the-documents-folder – dokun1