1. 程式人生 > >iOS中儲存圖片到相簿中的兩種方式

iOS中儲存圖片到相簿中的兩種方式

方式一:

UIImageWriteToSavedPhotosAlbum(self.imageV.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{

if (error) {

        [SVProgressHUDshowErrorWithStatus:@"儲存失敗"];

    }else{

        [SVProgressHUDshowSuccessWithStatus:@"儲存成功"];

    }

}

方式二:

NSError * error = nil;

__blockNSString * assetID = nil;

    [[PHPhotoLibrarysharedPhotoLibrary] performChangesAndWait:^{

       assetID =  [PHAssetChangeRequestcreationRequestForAssetFromImage:self.imageV.image

].placeholderForCreatedAsset.localIdentifier;

    } error:&error];