儲存檔案
//下載完成時存檔 NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/ooxx.png"]; [fileData writeToFile:path atomically:YES];
判斷檔案存在直接顯示,否則就開始下載
NSFileManager *fmng = [NSFileManager defaultManager]; //印出路徑可以從資料夾中查看 NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/ooxx.png"]; if ([fmng fileExistsAtPath:path]) { NSData *imgData = [NSData dataWithContentsOfFile:path]; imgv.image = [[UIImage alloc] initWithData:imgData]; } else { //下載檔案 [self getData]; }
留言
張貼留言