Forum Xamarin.iOS


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Export PHAsset? RequestExportSession always "An unknown error occurred (-12105)"

Ron.SijmRon.Sijm USMember ✭✭

Hi there,

A colleague wants a feature in his project to save photos locally from the gallery. He wants to use Photokit for that since the framework he's using now is marked obsolete. I'm supposed to make a PoC for this, but there doesn't seem to be much information on this.

This is what I have:

    void SaveVideo(object sender, EventArgs e)
        PHImageManager.DefaultManager.RequestExportSession(Asset, new PHVideoRequestOptions() { NetworkAccessAllowed = true }, "AVAssetExportPresetLowQuality", ResultHandler);           

    private void ResultHandler(AVAssetExportSession exportSession, NSDictionary info)
        var documents = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User)[0].Path;
        var outputPath = Path.Combine(documents, "");

        var outputURL = new NSUrl(outputPath);

        exportSession.OutputUrl = outputURL;
        exportSession.OutputFileType = AVFileType.QuickTimeMovie;

            () =>
                    // This always fails

And its always giving me this exception

  exportSession.Error.Description "Error Domain=AVFoundationErrorDomain Code=-11800 \"The operation could not be completed\" UserInfo={NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x7c0b8d30 {Error Domain=NSOSStatusErrorDomain Code=-12105 \"(null)\"}, NSLocalizedFailureReason=An unknown error occurred (-12105)}"   string

I've tried messing around with this, changing parameters, file types, and output paths, but I keep getting the same error.

I've added the entire solution as attachment, in case someone wants to try it themselves


  • bradmbradm AUMember ✭✭✭

    Did you ever find a solution for this?

  • FahadRehmanSFahadRehmanS PKMember ✭✭

    Ok I was able to get this work, You need add the out put file path with NSUrl.FromFilename

    var options = new PHVideoRequestOptions();
    options.Version = PHVideoRequestOptionsVersion.Current;
         PHImageManager.DefaultManager.RequestExportSession(phAsset, options, AVAssetExportSession.PresetHighestQuality, (exportSession, info) =>
                    exportSession.OutputUrl = NSUrl.FromFilename(UploadHelper.UploadsDirectory + Guid.NewGuid().ToString() +  ".MOV");   // File Path and check if there does file exist already with same name
                    exportSession.OutputFileType = AVFileType.QuickTimeMovie;
                    exportSession.ExportAsynchronously(() =>
                        switch (exportSession.Status)
                            case AVAssetExportSessionStatus.Failed:
                                CommonIOSUtil.DisplayToast("An Error Occured");
                            case AVAssetExportSessionStatus.Completed:
                                this.DismissViewController(exportSession.OutputUrl.RelativePath, CustomMashupFormat.Video, phAsset.LocalIdentifier);
  • RavnRavn USMember

    Thanks Fahad, you just saved me from hours of debugging! :smile:

  • noob8129noob8129 Member ✭✭

    @FahadRehmanS In my case, exportSession is always null. Any reason why?

Sign In or Register to comment.