2011-07-15 8 views

答えて

2
NSString *docs = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0]; 
NSString *dir = @"coffeeShops"; 
NSString *destPath = [docs stringByAppendingPathComponent:dir]; 

// check if the destination directory exists, if not create it 
BOOL isDirectory; 
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:destPath isDirectory:&isDirectory]; 
if(!exists || !isDirectory) { 
    NSError *error = nil; 
    [[NSFileManager defaultManager] createDirectoryAtPath:destPath withIntermediateDirectories:NO attributes:nil error:&error]; 
    if(error != nil) { 
     // should do error checking here 
     NSLog(@"%@",[error localizedDescription]); 
    } 
} 

NSString *fileName = @"image.jpg"; 
NSString *path = [destPath stringByAppendingPathComponent:fileName]; 

[UIImageJPEGRepresentation(image) writeToFile:path atomically:YES]; 
関連する問題