0

I have an app that is configured so that PDFs in other applications such as mail, I can hold down on the PDF and it will have the open to "open in" my app; I have that working and my app opens, but now I want to display that document in my app, how do I do that? I am pretty sure that I have to use AppDelegate, but I just started using Swift and am completely lost and cannot find a tutorial that helps with this task, so any help would be appreciated.

AppDelegate.swift

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
let UIApplicationLaunchOptionsURLKey: String = ""

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    if UIApplicationLaunchOptionsURLKey.isEmpty {
        print("String is empty.")
    }
    else{

    let alertView:UIAlertView = UIAlertView()
    alertView.title = "PDF UPLOAD"
    alertView.message = "??"
    alertView.delegate = self
    alertView.addButtonWithTitle("OK")
    alertView.show()
    }
    return true
}

1 Answers1

0

In your AppDelegate's didFinishLaunchingWithOptions, you can handle setting up your UI to display the PDF. You can use UIWebView to render the document.

iPhone : can we open pdf file using UIWebView?

EDIT:

This link explains the launch options you can listen for in AppDelegate. didFinishLaunchingWithOptions. UIApplicationLaunchOptionsURLKey will contain the URL pointing to your file.

Community
  • 1
  • 1
72A12F4E
  • 1,744
  • 1
  • 14
  • 28
  • But how do I actually access that PDF when it is opened in my app? – U.S. Coding Team - Benchwarmer Jul 21 '15 at 19:48
  • I found this link that might help: https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentInteraction_TopicsForIOS/Articles/OpeningSupportedFileTypes.html#//apple_ref/doc/uid/TP40010412-SW1 – 72A12F4E Jul 21 '15 at 19:59
  • So I added some of my AppDelegate.swift code above, I am trying to open the app with a PDF, and if it does I assume with the code I wrote it would display an alertview, I did this because I realized if I close the app on my iPhone then the connection is gone with the console on xcode. Either way, I was unable to get the alertview to display which assumes I am doing something wrong here. – U.S. Coding Team - Benchwarmer Jul 21 '15 at 20:33
  • Try [this](http://stackoverflow.com/questions/9040896/why-is-showing-a-uialertview-in-applicationdidfinishlaunchingwithoptions-causi) if you NEED to display an alert here. I would recommend instantiating a view controller that can handle this interaction for you. – 72A12F4E Jul 21 '15 at 20:38
  • I don't need an alert I am just using it to test my method – U.S. Coding Team - Benchwarmer Jul 21 '15 at 20:51
  • Try instantiating a view controller, setting a URL property, and then set that view controller as the rootViewController. Then, handle your interactions from your PDFUploadViewController, and segue back into your normal application flow. – 72A12F4E Jul 21 '15 at 20:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83909/discussion-between-john-smith-and-u-s-coding-team-benchwarmer). – 72A12F4E Jul 21 '15 at 20:59