Monotouch - QLPreviewController problem

I am trying to use QLPreviewController to view a PDF file and send it, but I have a problem with the action button after previewing the PDF document.

When I click the action button (top right), the application crashes and I get: "Unhandled managed exception: Objective-C exception is thrown. Name: NSInternalInconsistencyException Cause: UIDocumentInteractionController: invalid scheme (null). (MonoTouch.Foundation.MonoTouchException) "

I did some research and I realized that this problem can occur if you download a file from the Internet or if the file type is not "file: // ..........". My NSUrl is in this format, so I don’t know why I have this error.

Does anyone have an idea?

thanks

Here is my code to call the controller:

QLPreviewController previewController= new QLPreviewController();             

previewController.DataSource=new MyQLPreviewControllerDataSource();     

this.PresentViewController(previewController,true, null);

This is my code for DataSource:

public class MyQLPreviewControllerDataSource : QLPreviewControllerDataSource { public     override int PreviewItemCount (QLPreviewController controller) {

    return 1;
}

public override QLPreviewItem GetPreviewItem (QLPreviewController controller, int index)
{

    string fileName = @"example.pdf";
    var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
    var library = Path.Combine (documents,fileName);
    NSUrl url = NSUrl.FromFilename (library);
    return new QlItem ("Title", url);
}
}

This is my code for the item:

public class QlItem : QLPreviewItem { string _title; Uri _uri;

public QlItem (string title, Uri uri) 
{ 
    this._title = title; 
    this._uri = uri; 
} 

public override string ItemTitle { 
    get { return _title; } 
} 

public override NSUrl ItemUrl { 
    get { return _uri; } 
} 

}

+2
source share
1 answer

Your QlItem class distinguishes the original NSUrl in Uri before returning it to NSUrl, and something is lost along the way.

It should look bigger:

    public class QlItem : QLPreviewItem 
    { 
        string title; 
        NSUrl uri; 

        public QlItem(string title, NSUrl uri) 
        { 
            this.title = title; 
            this.uri = uri; 
        } 

        public override string ItemTitle { 
            get { return title; } 
        } 

        public override NSUrl ItemUrl { 
            get { return uri; } 
        } 
    }                
+2
source

Source: https://habr.com/ru/post/1527946/


All Articles