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; }
}
}
source
share