緩存URL圖片:
-(void)LoadImage{
NSURL *url = [NSURL URLWithString:@"http://~.jpg"];
NSData *data = [NSData dataWithContentsOfURL:url];
[data writeToFile:[self GetTempPath:@"test.png"] atomically:NO];
UIImage *img = [UIImage imageWithData:data];
}
-(NSString *)GetTempPath:(NSString*)filename{
NSString *tempPath = NSTemporaryDirectory();
return [tempPath stringByAppendingPathComponent:filename];
}
如果要確認文件存在否:
-(BOOL)isExistsFile:(NSString *)filepath{
NSFileManager *filemanage = [NSFileManager defaultManager];
return [filemanage fileExistsAtPath:filepath];
}
BOOL exist = [self isExistsFile:[self GetTempPath:@"test.png"]];
如果要存在Document內,在GetTempPath內改成:
NSArray *dirpathary = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *tempPath = [[dirpathary objectAtIndex:0] retain];
沒有留言:
張貼留言
歡迎大家留言提問,我會答的都會盡力回答!
如果太久沒出現回應就是我又忘記回來看留言了TAT