I'm using Xamarin to develop an iPad iOS 7.0 app and I want to use the UIDocumentInteractionController to display a PDF. I used various examples on Stack Overflow to get the proper implementation but nothing has worked.
Here is a link on Stack Overflow which I used for reference.
Monotouch open document - UIDocumentInterationController
I also used this objective C tutorial but have been unable to properly translate this code into C#. http://code.tutsplus.com/tutorials/previewing-and-opening-documents-with-uidocumentinteractioncontroller--mobile-15130
Here is my code. I currently have a toolbar button which, when clicked, should trigger the PDF preview. Nothing happens when I click the button.
What is it that I am missing for this to work?
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
documentInteractionController = new UIDocumentInteractionController ();
string fileName = "Content/test.pdf";
string localURL = Path.Combine (NSBundle.MainBundle.BundlePath, fileName);
NSUrl URL = new NSUrl(localURL, false);
documentInteractionController = UIDocumentInteractionController.FromUrl (URL);
documentInteractionController.Delegate = new UIDocumentInteractionControllerDelegateClass(this);
toolbarButton.Clicked += delegate(object sender, EventArgs e){
InvokeOnMainThread(delegate{
documentInteractionController.PresentOpenInMenu(View.Frame, View, true);
});
};
}
public class UIDocumentInteractionControllerDelegateClass : UIDocumentInteractionControllerDelegate
{
UIViewController viewC;
public UIDocumentInteractionControllerDelegateClass(UIViewController controller)
{
viewC = controller;
}
public override UIViewController ViewControllerForPreview (UIDocumentInteractionController controller)
{
return viewC;
}
public override UIView ViewForPreview (UIDocumentInteractionController controller)
{
return viewC.View;
}
public override RectangleF RectangleForPreview (UIDocumentInteractionController controller)
{
return viewC.View.Frame;
}
}