美文网首页
iOS 保存Gif到相册

iOS 保存Gif到相册

作者: 米修斯_ | 来源:发表于2019-08-26 11:38 被阅读0次
    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到相册

          本文链接:https://www.haomeiwen.com/subject/bqjrectx.html