iOS - не удается сохранить .MOV & .jpg как LivePhoto - отображается ошибка NSCocoaErrorDomain Code = -1 [Цель C] - PullRequest
0 голосов
/ 07 марта 2019

Я хочу создать живое фото программно со смесью 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

...