【发布时间】:2011-09-16 12:55:52
【问题描述】:
为什么如果我使用NSTemporaryDirectory保存我的图像,图像被保存到
/var/folders/oG/oGrLHcAUEQubd3CBTs-1zU+++TI/-Tmp-/
并没有进入
/Users/MyMac/Library/Application Support/iPhone Simulator/4.3.2/Applications/A685734E-36E9-45DD-BBE7-0A46F8F91DAF/tmp
这是我的代码:
-(NSString *)tempPath
{
return NSTemporaryDirectory();
}
-(void) saveMyFoto
{
NSString *urlNahledu = [NSString stringWithFormat:@"%@%@%@",@"http://www.czechmat.cz", urlFotky,@"_100x100.jpg"];
NSLog(@"%@", urlNahledu);
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlNahledu]]];
NSData *data = [NSData dataWithData:UIImageJPEGRepresentation(image, 0.8f)];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSLog(@"%@ %@", paths, [self tempPath]);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:@"pkm.jpg"];
[data writeToFile:localFilePath atomically:YES];
}
【问题讨论】:
-
本帖讲解iOS应用的所有目录,保存,删除kmithi.blogspot.in/2012/08/…
-
UIImageJPEGRepresentation()已经返回NSData *- 为什么在使用之前将它传递给dataWithData:?我想知道你是否知道一些我不知道的事情......