c# - Xamarin iOS: How to open a .pdf file using the default reader? -


i'm using xamarin ios. i'd have our application open .pdf file in default reader. android managed done following two-fold process: (1) copy file assets folder android device's downloads folder, , (2) starting activity view file.

i cannot find similar resources ios. don't want use control in xamarin website, involves downloading lots of javascript (?) code, making size of app bigger, , doesn't support pinching screen zoom. want use os's default pdf reader.

thank you.

method 1:

set build action bundleresource. can set build action file right-clicking on file , and choosing build action in menu opens.
create uiwebview , add view:

webview = new uiwebview (view.bounds); view.addsubview(webview); 

load file using nsurl , nsurlrequest classes:

string filename = "loading web page.pdf"; // remember case-sensitive string localdocurl = path.combine (nsbundle.mainbundle.bundlepath, filename); webview.loadrequest(new nsurlrequest(new nsurl(localdocurl, false))); webview.scalespagetofit = true; 

method 2:

public void openfile (nsurl fileurl) {     var doccontrol = uidocumentinteractioncontroller.fromurl (fileurl);      var window = uiapplication.sharedapplication.keywindow;     var subviews = window.subviews;     var lastview = subviews.last ();     var frame = lastview.frame;      doccontrol.presentopeninmenu (frame, lastview, true); } 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -