Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法将保存的.mov文件移动到照片卷_Ios_Objective C_Unity3d - Fatal编程技术网

Ios 无法将保存的.mov文件移动到照片卷

Ios 无法将保存的.mov文件移动到照片卷,ios,objective-c,unity3d,Ios,Objective C,Unity3d,我有一个可以录制视频并保存到iPad的库。保存后,我想将其移动到照片库中,但我无法使其工作 BOOL success = [videoWriter finishWriting]; if (!success) { NSLog(@"finishWriting returned NO"); } [self cleanupWriter]; id delegateObj = self.delegate; NSString

我有一个可以录制视频并保存到iPad的库。保存后,我想将其移动到照片库中,但我无法使其工作

 BOOL success = [videoWriter finishWriting];
        if (!success) {
            NSLog(@"finishWriting returned NO");
        }

    [self cleanupWriter];

    id delegateObj = self.delegate;
    NSString *outputPath = [[NSString alloc] initWithFormat:@"%@/%@", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0], @"output.mov"];
    NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputPath];

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    if([library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputURL]){
    [library writeVideoAtPathToSavedPhotosAlbum:outputURL completionBlock:^(NSURL *assetURL, NSError *error){
        if(error){
            NSLog(@"Failed to save movie");
        }
        else{
            NSLog(@"Saved movie");
        }
    }];
    }
    else{
        if(UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(outputPath)){
            UISaveVideoAtPathToSavedPhotosAlbum(outputPath, nil, nil, nil);
        }
        else{
            NSLog(@"Didn't save movie");
        }
    }
这将始终返回未保存的电影。这表明视频不兼容,无法放入卷中。问题是,我看不出它有什么问题,因为我在iOS上运行它,所以在它出现在卷中之前我无法查看视频

我已经在这上面呆了一段时间,希望有人能给我一些建议。

试试这段代码-

NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];

    if (CFStringCompare((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo)
    {
        NSString *moviePath = [[info objectForKey: UIImagePickerControllerMediaURL] path];

        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath))
        {
            UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
        }
    }

谢谢你的快速回复。你的代码在NSString*moviePath=[[info知道为什么吗?在-(void)imagePickerController:(UIImagePickerController*)中写入上述代码picker完成了PickingMediaWithInfo:(NSDictionary*)infoHmm我不相信在我当前的项目中会进行回调…我没有让用户选择视频,但我的库会记录屏幕并将其保存到一个文件中。我如何强制调用该方法?检查这可能会帮助您,这对我来说是不可能的。我上面显示的代码被编译到库中,并从Unity项目调用。我没有ImagePickerControl,我无法在我的项目中使用它。无论如何,现在的情况不是这样。另外,除了获取URL的方式之外,你给我的代码和我的代码有什么区别?我的上一个if和你的上一个if是相同的。