PHPhotoLibrary save a gif data

前端 未结 3 2050
自闭症患者
自闭症患者 2021-01-06 16:48

I can\'t find a similar method to ALAssetsLibrary->writeImageDataToSavedPhotosAlbum in the new PHPhotoLibrary since ALAssetsLibrary deprecated in iOS 9 I can\'t save GIF pro

相关标签:
3条回答
  • 2021-01-06 16:59

    I used NSData to save the gif image, ALAssetsLibrary method UIImageWriteToSavedPhotosAlbum deprecated after iOS8,The api says we can use PHAssetCreationRequestmethod [[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:data options:options]; to save this gif image data, so you can use url request to save gifs as well

    codes are follows:

    NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"gif"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init];
        [[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:data options:options];
    } completionHandler:^(BOOL success, NSError * _Nullable error) {
        NSLog(@":%d",success);
    }];
    
    0 讨论(0)
  • 2021-01-06 17:19

    I solved my issue by creating temp file and using :

    creationRequestForAssetFromImageAtFileURL

    0 讨论(0)
  • 2021-01-06 17:20

    I've save gif file successfully to Photos Gallery by using Photos Framework

    PHPhotoLibrary.shared().performChanges ({
        let url = URL(fileURLWithPath: "your file path")
        PHAssetChangeRequest.creationRequestForAssetFromImage(atFileURL: url)
      }) { saved, error in
        if saved {
          print("Your image was successfully saved")
        }
      }
    

    Hope this help!

    0 讨论(0)
提交回复
热议问题