-1

I'm having trouble finding a solution to this problem. My app will be used to sign certain actions. The flow will be like this:

  1. User want to sign in to a website using any browser.
  2. User enters credentials.
  3. User gets redirected to my app using a custom url scheme.
  4. User uses his signature code to approve.
  5. User gets redirected back to the same page in the web browser.

It's the last part I'm having problem figuring out. How do I re-open the web browser with the same tab when user is done?

1 Answers1

0

You will get the url in below function after callback in app from browser :

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {

 if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
        let url = userActivity.webpageURL!
        print(url)

    }
}

Then you need to check like this

if let url = URL(string: urlSting.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!), UIApplication.shared.canOpenURL(url) {
    UIApplication.shared.openURL(url!)
}

or url is perfect then you can simply open like this:

if let url = URL(string: urlSting), UIApplication.shared.canOpenURL(url) {
    UIApplication.shared.openURL(url)
}

You can also store browser url in user default until user complete the signature process then redirect that url in web browser

Dhaval Raval
  • 594
  • 2
  • 7
  • Thank you for the quick response but this function does not get called at all. – Joacim Wideving Dec 17 '19 at 12:47
  • try after change [Any] to [UIUserActivityRestoring]? in userActivity function.. it must be called.. it works my side – Dhaval Raval Dec 17 '19 at 12:55
  • Are you sure that function gets called when user clicks on a link in a web browser on their phone? – Joacim Wideving Dec 18 '19 at 07:26
  • Yes i have done deep linking and universal linking.. this function gets called when user come back to app from browser and you can get the browser url there – Dhaval Raval Dec 18 '19 at 07:32
  • if you are working in iOS 13 then this method might not called because it introduced SceneDelegate.. refer [this](https://stackoverflow.com/questions/59076416/url-opening-swift-app-open-works-called-function-does-not-work) solution. – Dhaval Raval Dec 18 '19 at 07:59
  • Ok, I think i see where the problem is, that function does not get called when using custom url schemes, it does however get called when using universal links. I will continue on my own from here. Thank you for your time. – Joacim Wideving Dec 18 '19 at 08:11