2017년 1월 12일 목요일

겔러리에 이미지/비디오 저장 하기 over iOS 8

#import <Photos/Photos.h>


- (IBAction)touchedImageSave:(id)sender {
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:_imageView.image];
        changeRequest.creationDate          = [NSDate date];
    } completionHandler:^(BOOL success, NSError *error) {
        if (success) {
            [[Util sharedInstance] showToastMessage:@"저장되었습니다."];
        }
        else {
            [[Util sharedInstance] showToastMessage:[NSString stringWithFormat:@"저장에 실패했습니다. (%@)", error.localizedDescription]];
        }
    }];

}



- (IBAction)touchedVideoSave:(id)sender {
    
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
     {
         NSURL *url = [NSURL URLWithString:_fileUrl];
         [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:url];
     }
                                      completionHandler:^(BOOL success, NSError *error)
     {
         if (success) {
             [[Util sharedInstance] showToastMessage:@"저장되었습니다."];
         }
         else {
             [[Util sharedInstance] showToastMessage:[NSString stringWithFormat:@"저장에 실패했습니다. (%@)", error.localizedDescription]];
         }
     }];
}

댓글 없음:

댓글 쓰기