0

This code open the acrobat reader

var url = new NSUrl($"com.adobe.adobe-reader://");
UIApplication.SharedApplication.OpenUrl(url);

I tried to give file path to this but i am getting error

var url = new NSUrl($"com.adobe.adobe-reader://{filepath}");

var url = new NSUrl($"com.adobe.adobe-reader:{filepath}");
amnk
  • 51
  • 6
  • 1
    Can you provide the detail of error .And what is your filepath,a URL or storage from phone? – Lucas Zhang Dec 11 '18 at 01:51
  • My file path is /var/mobile/Containers/Data/Application/02EBA058-E520-4E36-BCCD-D3D86781A583/Documents/files/Temp/SJA V001-2.pdf – amnk Dec 11 '18 at 02:31

1 Answers1

2

I am not sure that you can open a file directly in another app with this method. Instead I think you need to use the UIDocumentInteractionController to open a popup that allows the user to select the app to open the PDF in. So try this:

NSUrl adobeUrl = new NSUrl($"com.adobe.adobe-reader:");
NSUrl fileUrl = NSUrl.FromFilename(filePath);
UIDocumentInteractionController docController = UIDocumentInteractionController.FromUrl(fileUrl);
if (UIApplication.SharedApplication.CanOpenUrl(adobeUrl))
{
    docController.PresentOpenInMenu(this.View.Frame, this.View, true);
}
else
{
    // throw error
}

Also you need to add the Adobe Reader URL Scheme to the Info.plist. Open your Info.plist in a text editor and put the following:

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>com.adobe.adobe-reader</string>
    </array>

right before the last tag, e.g.

<plist version="1.0">
<dict>
    ...
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>com.adobe.adobe-reader</string>
    </array>
</dict>
</plist>

Without that, you will fail the CanOpenUrl test, so that is why nothing happened... though if you had looked in the Application output, iOS did send a message that you need to do this, e.g.:

-canOpenURL: failed for URL: "com.adobe.adobe-reader:" - error: "This app is not allowed to query for scheme com.adobe.adobe-reader"

I believe that for something like var url = new NSUrl($"com.adobe.adobe-reader://{filepath}"); to work, the file actually needs to be in Adobe Acrobat's file container already. See this SO post for more info: https://stackoverflow.com/a/21913788/2913599 [NOTE: I could not get this method to work, even with the pdf already in Adobe Acrobat's files]

jgoldberger - MSFT
  • 5,978
  • 2
  • 20
  • 44
  • I tried your code. But nothing happened. but no errors. I had added docController.PresentPreview(true); Can't add docController.PresentOpenInMenu(this.View.Frame, this.View, true); – amnk Dec 11 '18 at 02:53
  • ops, forgot to mention, you need to add the adobe scheme to the Info.plist Will update answer. – jgoldberger - MSFT Dec 11 '18 at 02:54
  • how to add it to info.plist – amnk Dec 11 '18 at 03:02
  • As I noted in my edited answer, open the Info.plist in a text editor. – jgoldberger - MSFT Dec 11 '18 at 03:03
  • Thanks for helping. I added it to plist. now i am not getting that Application output error msg you have mention above. But still nothing happened. – amnk Dec 11 '18 at 03:29
  • Is there any exception or other error message? And by "nothing happened" do you mean that the popup to select Acrobat Reader app to open PDF did not pop up? – jgoldberger - MSFT Dec 11 '18 at 20:57
  • I uploaded a sample that works here: https://www.dropbox.com/s/pnmina7naensgfv/AcroReaader.zip?dl=0 – jgoldberger - MSFT Dec 11 '18 at 21:07
  • Oh, for the sample, you have to launch the app, close and get a PDF from somewhere else on the iOS device and use the Share icon to open the PDF in the sample app. The PDF will be copied to the apps internal directory, with a path similar to what you are using, then you click the button in the app to bring up the dialog to open the PDF in Adobe Acrobat. – jgoldberger - MSFT Dec 11 '18 at 23:51
  • This is the code i am using now. https://drive.google.com/open?id=1_EvuZO3__ULJZXnlB9FOy3ZlgKmX5-pA – amnk Dec 12 '18 at 02:35
  • first i am save my file to icloud and opening it from acrobat. now its saved and when its opening its shows a dialog box with copy to acrobat. that is the issue now. – amnk Dec 12 '18 at 02:42
  • Yes, that dialog box is what you want to open the PDF in Acrobat. And yes, it will copy the PDF to the Acrobat App. I do not know of any other way to do this. I have not looked at your code yet, but it sounds like you are getting the correct behavior that I was demonstrating. – jgoldberger - MSFT Dec 12 '18 at 03:05
  • I thought this was the issue for that. UIView presentingView = UIApplication.SharedApplication.KeyWindow.RootViewController.View; PreviewController.PresentOpenInMenu(CGRect.Empty, presentingView, true); – amnk Dec 12 '18 at 03:09