1

I've implemented an URL scheme for the redirect back to my app after payment. When a webpage direct back to my app, the app should open a navigation controller over the current view. (So open it modal).

How to do this from the AppDelete in the func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool-method?

Thanks in advance!

Rick de Jong
  • 237
  • 1
  • 4
  • 12

2 Answers2

1

If the view controller that submitted the request is the one that should display the modal, I'd suggest a different approach. I would suggest defining a notification in the notification center that you use to notify the current view controller.

In your view controller, make a call to one of the Notification center methods like addObserver(forName:object:queue:using:) to observe your notification.

Then call a Notification method like post(name:object:) from your app delegate's implementation of application(_:open:options:) when you get the expected URL.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
0

Are you using a storyboard or you manually create the window in the delegate? If you have access to the window, you can do this:

window?.rootViewController?.present(yourViewController, animated: true, completion: nil)

Otherwise, it should work in all cases:

UIApplication.shared.keyWindow?.rootViewController?.present(yourViewController, animated: true, completion: nil)
Robert D. Mogos
  • 900
  • 7
  • 14
  • Hi there! I'm using storyboards. Is it possible to do this with a modal transition? – Rick de Jong Sep 28 '17 at 15:01
  • It is a modal transition. You can customise it by doing `yourViewController. modalTransitionStyle` or customise the `yourViewController. modalPresentationStyle` – Robert D. Mogos Sep 28 '17 at 15:06