0

I have to design an iOS app which will download a pdf file and there will be an "open in" by UIActivityViewController (UIActivity subclassing) .Using OpenUrl I sent data to the other application and I can get pdf data in second application.

But I want the same functionality with Safari also. I want to see the second app in safari "open in" and once user get some pdf in Safari, user can click open in to get pdf data in second application.

- (void)performActivity {

    NSString *urlstring=@"ran/jan/jena/getit";
    NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"ranjantest:///%@",urlstring]];
    BOOL checkurl=[[UIApplication sharedApplication]canOpenURL:URL];
    if(checkurl){
        [[UIApplication sharedApplication] openURL:URL];
    }else{
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"No suitable App installed" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }

}

Any suggestion how to do it ?

Getz
  • 3,983
  • 6
  • 35
  • 52
  • Have you had a look at the `UIDocumentInteractionController` (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDocumentInteractionController_class/) This I believe allows you to download your pdf or select one already stored on the device and provides you with apps that will allow you to view that pdf. You can use the `interactionControllerWithURL:` to open to the PDF Document and then use one of the `Presenting and Dismissing Menus` to present the available options to the user – Popeye Mar 19 '15 at 09:22
  • You app need to register and handle custom URL scheme. Take a look at Apple document here: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html – Kilogen9 Mar 19 '15 at 09:25
  • But i want to see my second app in safari "open in". Sending data from one application to other application is working fine using openurl. But i want to open some pdf in safari and from safari "open in " need to open my second app that can receive the pdf data . Hope i am clear in my question – ranjanjena12345 Mar 19 '15 at 09:33

1 Answers1

0

OK to get your application to appear in the open in/with option of safari for PDFs what you need to do is set your application to be associate with that specific document type in xcode.

In the Info tab, you would add a Document Type and specify PDF this will associate your application to PDF documents so when you go to safari and download a PDF document it will allow you to use the open in/with option and select your application.

Have a read of the Apple Documentation for Document Type here but by the looks of it you might still need to implement the UIDocumentInteractionController but that Apple Document explains all.

Popeye
  • 11,839
  • 9
  • 58
  • 91