これも以前に調べて自分でもコード書いていた内容。
どうしてこうも憶えが悪いのか私。orz
ヘッダーでALAssetsLibrary をimport してから、(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 内にちょいちょいと追記するだけでOKです。
.h ファイル
#import <UIKit/UIKit.h> #import <AssetsLibrary/AssetsLibrary.h> @interface MyViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> // 以下略
.m ファイル
- (void)imagePickerController:(UIImagePickerController *)ipc didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = info[UIImagePickerControllerOriginalImage];
NSMutableDictionary *exif = info[UIImagePickerControllerMediaMetadata];
ALAssetsLibrary *assetsLibrary = [ALAssetsLibrary new];
[assetsLibrary writeImageToSavedPhotosAlbum:image.CGImage metadata:exif completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
NSLog(@"Save image failed.n %@", error);
}
}];
[self dismissViewControllerAnimated:YES completion:nil];
}