0

I'm working on an iOS Project using Swift. I have a ViewController that is embedded in a UINavigationController. I have my app associated with PDF files in plist. The user can open a PDF emailed to them in the project. I know this then deals with:

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {

    if url != "" {

        // Load from Mail App

        incomingFileTransfer = url

        incomingStatus = "Incoming"

        /*let rootViewController = self.window!.rootViewController
        let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let setViewController = mainStoryboard.instantiateViewControllerWithIdentifier("MainMenu") as! MainMenuViewController
        rootViewController?.navigationController?.popToViewController(setViewController, animated: false)*/

    } else {

        // Regular Load

        print("App Delegate: No incoming file")

        incomingFileTransfer = nil

    }  

    return true
} 

If the user is in another area of the app, and they open the app again from the PDF, the app opens back to the area where they were. I want it to open to the first loaded ViewController always. I looked here and tried to implement this in my section above in AppDelegate with no luck. Can someone please help with this particularly in Swift? I'm not real great with converting Objective-C to Swift.

My ViewController has a Title set as MainMenu:

enter image description here

This ViewController has the UINavigationController set as the Initial View and a name of Main:

enter image description here

The Storyboard has a Storyboard ID of Main within the UINavigationController Identity Inspector:

enter image description here

Update:

Sorry. The url is assigned to a Global Variable that is then loaded into another ViewController that has a WebView.

Community
  • 1
  • 1
ChallengerGuy
  • 2,385
  • 6
  • 27
  • 43
  • *tried to implement this with no luck* The system gave you a URL and you didn't do anything with it, or remove any pushed view controllers from the navigation controller stack. Where did you open the URL, or get your navigation controller's initial view controller to display the PDF? –  Feb 04 '16 at 17:09
  • Sorry. Please see update. – ChallengerGuy Feb 04 '16 at 17:16
  • 1
    http://stackoverflow.com/questions/8329999/restart-iphone-application-from-the-very-beginning This post should do what you're looking for. – NSGangster Feb 04 '16 at 17:21
  • What would happen if you uncommented the code? And is the code doing anything specific with the URL? How is the initial view controller supposed to know what PDF to display? –  Feb 04 '16 at 17:21
  • Uncommenting the code does nothing. I tried unsuccessfully with it. – ChallengerGuy Feb 04 '16 at 17:35
  • @NSGangster, that worked perfectly! – ChallengerGuy Feb 04 '16 at 17:38

1 Answers1

0

Looking here as @NSGangster suggested, I went into my plist and added the following:

enter image description here

Now my app re-opens as if it was the first time.

Community
  • 1
  • 1
ChallengerGuy
  • 2,385
  • 6
  • 27
  • 43