2

I am trying to redirect to an app after launching a browser window using UIApplication.shared.open.

My code looks like this:

    let url = URL(string: "https://example.com/endpoint")!

    UIApplication.shared.open(url, options: [:], completionHandler: { (success) in

    })

I need to launch a browser window to generate a user fingerprint that will be the same fingerprint as the browser that the user got sent to the App Store with. However once the browser window opens and this fingerprint is generated, I no longer need the window.

Is there a way to really quickly open a window to generate this fingerprint and then close it back and hand control back to the app?

The fingerprint is being generated on the server end - all I need to do is make sure that the same browser that the user was sent to the App Store with is the same browser opened now. The default browser seems like a "good enough" situation for now.

Steven Matthews
  • 9,705
  • 45
  • 126
  • 232

1 Answers1

1

Have you looked into using SFSafariViewController? It would allow you to present a browser within the app in which at a later point you can dismiss as it's an instance of a UIViewController.

Alternatively you can use URL schemes or universal links to redirect back into the app after a fingerprint is generated i.e. https://stackoverflow.com/a/25883274/4698501

Patrick
  • 2,035
  • 17
  • 27
  • As far as I could tell it generated a different fingerprint as it had a different user agent – Steven Matthews Apr 15 '18 at 00:23
  • I'll double check that though. – Steven Matthews Apr 15 '18 at 00:25
  • Seems like you're right judging by this post: https://forums.developer.apple.com/thread/12986 – Patrick Apr 15 '18 at 00:25
  • Yeah, that's consistent with what I saw earlier I believe – Steven Matthews Apr 15 '18 at 00:26
  • I could go through the trouble of generating cross browser fingerprinting but that will be a huge, huge headache vs just calling the same browser if possible – Steven Matthews Apr 15 '18 at 00:27
  • Can you make use of URL schemes whereby after generating the fingerprint the website redirects to a URL scheme your app has registered? i.e. https://stackoverflow.com/a/25883274/4698501 – Patrick Apr 15 '18 at 00:28
  • I'm not super familiar with this, but that looks like it might work. – Steven Matthews Apr 15 '18 at 00:29
  • This also seems like it might be a solution: https://developer.apple.com/library/content/documentation/General/Conceptual/AppSearch/UniversalLinks.html – Steven Matthews Apr 15 '18 at 00:33
  • That is true however I believe that's meant to be used where you have content that can be displayed both on an app or website where else in your case you don't want to fall back to a website, you want them to go to the app every time after they authenticate. – Patrick Apr 15 '18 at 00:36
  • 1
    Yes, I agree with you. URL schemes seem to be the Apple preferred method for deeplinking, which this is more or less an implementation of it seems. So it sounds like that's my solution. – Steven Matthews Apr 15 '18 at 00:37
  • Actually, in order to redirect without a prompt, it appears like universal links are in fact required. https://stackoverflow.com/questions/43510652/custom-url-scheme-without-confirmation-prompt-swift?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Steven Matthews Apr 15 '18 at 02:58
  • Valid point, looks like universal links is the way to go for you :) – Patrick Apr 15 '18 at 03:01