画像を保存する
画像をurlにわざわざ取りにいくのは時間もかかるしめんどくさいので、アプリ内に保存してしまいましょう。LINEとかはそうしてますよね。オフラインでも友達の写真は表示されるのでわかります。
以下のコードでOK→(参照もと: http://fitss.jp/blog/2013/05/xcodeImagePicker.shtml)
UIImage *image = self.image.image;
NSData *imageData = UIImagePNGRepresentation(image);
NSString *path = [NSString stringWithFormat:@"%@/image.png", [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]];
if ([imageData writeToFile:path atomically:YES]) {
NSLog(@"save successs");
} else {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"エラー"
message:@"画像が保存できませんでした。あとでもう一度お試しください"
delegate:self
cancelButtonTitle:@"確認"
otherButtonTitles:nil, nil];
[alert show];
return;
}
そしてこちらが保存した写真を取り出す方法
画像を取り出す
NSData *imageData = [NSData dataWithContentsOfFile:[imageLinks objectAtIndex:i]]; UIImage *image = [[UIImage alloc]initWithData: imageData];

