小编vos*_*osy的帖子

如何将图像保存到我的应用程序的tmp目录?

为什么如果我NSTemporaryDirectory用来保存我的图像,图像就会保存到

在/ var /文件夹/ 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];
}
Run Code Online (Sandbox Code Playgroud)

iphone xcode tmp

21
推荐指数
2
解决办法
2万
查看次数

标签 统计

iphone ×1

tmp ×1

xcode ×1