Ios 视频文件仅导出到照片应用程序?

Ios 视频文件仅导出到照片应用程序?,ios,objective-c,cocoa-touch,avfoundation,alassetslibrary,Ios,Objective C,Cocoa Touch,Avfoundation,Alassetslibrary,在我的应用程序中,我允许用户存储已编辑的视频。我将其保存到photos应用程序和文档目录中进行调试。然而,视频只保存到相册,而不是我的应用程序,我不知道为什么。以下是我正在做的: - (void) mergeVideos{ //do some neat editing NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSSt

在我的应用程序中,我允许用户存储已编辑的视频。我将其保存到photos应用程序和文档目录中进行调试。然而,视频只保存到相册,而不是我的应用程序,我不知道为什么。以下是我正在做的:

- (void) mergeVideos{
    //do some neat editing

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

    NSString *tempPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@_stacked.mov", [[self.firstVideo.videoURL lastPathComponent] stringByDeletingPathExtension], [[self.secondVideo.videoURL lastPathComponent]stringByDeletingPathExtension]]];

    NSURL *url = [NSURL fileURLWithPath:tempPath];

    AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetMediumQuality];
    exporter.outputURL=url;
    [exporter setVideoComposition:MainCompositionInst];
    exporter.outputFileType = AVFileTypeQuickTimeMovie;

    NSLog(@"EXPORT PATH IS %@",exporter.outputURL);

    [exporter exportAsynchronouslyWithCompletionHandler:^
     {
         dispatch_async(dispatch_get_main_queue(), ^{
             [self exportDidFinish:exporter];
         });
     }];
}

- (void)exportDidFinish:(AVAssetExportSession*)session
{
    NSURL *outputURL = session.outputURL;
    //NSLog(@"OUTPUT URL: %@",outputURL);
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputURL]) {
        [library writeVideoAtPathToSavedPhotosAlbum:outputURL
                                    completionBlock:^(NSURL *assetURL, NSError *error){
                                        dispatch_async(dispatch_get_main_queue(), ^{
                                            if (error) {
                                                NSLog(@"writeVideoToAssetsLibrary failed. Error: %@", error);
                                            }else{
                                                AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
                                                _managedObjectContext = [appDelegate managedObjectContext];
                                                Video *video = [NSEntityDescription insertNewObjectForEntityForName:@"Video" inManagedObjectContext:_managedObjectContext];

                                                [video setVideoURL:[NSString stringWithFormat:@"%@",outputURL]];
                                                NSError *error = nil;
                                                if (![_managedObjectContext save:&error]) {
                                                }
                                                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ALERT" message:@"SUCCESS" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
                                                [alert show];
                                                NSLog(@"Successfully written!");
                                            }

                                        });

                                    }];
    }
}