iOS 保存Gif到相册

dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSString *gifURL = @"https://static.dongtu.com/netpic/2019072614023570OLJTTM5VQTTVO3.gif";
        NSData *gifData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:gifURL]];
        NSDictionary *metadata = @{@"UTI":(__bridge NSString *)kUTTypeGIF};
        [_assetsLibrary writeImageDataToSavedPhotosAlbum:gifData metadata:metadata completionBlock:^(NSURL *assetURL, NSError *error) {
            if (error == nil) {
                NSLog(@"SaveSuccess");
            }else{
                NSLog(@"SaveFailed");
            }
        }];
    });
dispatch_async(dispatch_get_global_queue(0, 0), ^{
    NSString *gifURL = @"https://static.dongtu.com/netpic/2019072614023570OLJTTM5VQTTVO3.gif";
    NSData *gifData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:gifURL]];
    [[PHPhotoLibrary sharedPhotoLibrary] performChangesAndWait:^{
        [[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:gifData options:nil];
    } error: nil];

你可能感兴趣的:(iOS 保存Gif到相册)