0

我想用 jpg 和 MOV 的混合物以编程方式创建实时照片。下面是我的实现代码

这些是文件 jpg 文件的链接 - http://18.220.72.107/hd_wallpapers/images/animation/43625_wallpaper-2.jpg

MOV 文件 - http://18.220.72.107/hd_wallpapers/images/animation/43625_wallpaper-2.MOV

我的 MOV 和 JPG 来自服务器。相同的代码适用于放置在本地文件中的项目。

        NSData *urlData = [NSData dataWithContentsOfURL:url];

    if ( urlData )
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString  *documentsDirectory = [paths objectAtIndex:0];

        NSString  *movFilePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"thefile.MOV"];

        NSData* imgData = [NSData dataWithContentsOfURL:jpegURL];

        if(imgData){

        NSString  *jpegFilePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"thefile.jpg"];

                [imgData writeToFile:jpegFilePath atomically:YES];
                [urlData writeToFile:movFilePath atomically:YES];

                NSURL* jpgFileUrl = [NSURL fileURLWithPath:jpegFilePath];
                NSURL* movFileUrl = [NSURL fileURLWithPath:movFilePath];

                [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{

                    PHAssetCreationRequest* request = [PHAssetCreationRequest creationRequestForAsset];

                    [request addResourceWithType:PHAssetResourceTypePhoto fileURL:jpgFileUrl options:nil];
                   [request addResourceWithType:PHAssetResourceTypePairedVideo fileURL:movFileUrl options:nil];


                } completionHandler:^(BOOL success, NSError * _Nullable error) {
                    if (success) {

                    } else {

                    }
                }];
        }
    }

每当代码执行时,它都会抛出Error Domain=NSCocoaErrorDomain Code=-1

4

0 回答 0