Home > Net >  Swift how to open many URL scheme
Swift how to open many URL scheme

Time:11-16

I want to make an app that opens many URL schemes.
To make it, I tried some ways:

  1. I used UIApplication.shared.open(url, options: [:], completionHandler: nil).
    But this way I must add the URL scheme in info.plist.
    And in info.plist I can add a maximum of 50 URL schemes.
    (I want to add over 50 URL schemes)

  2. I tried using WKWebView.
    But The WKWebView doesn't handle non-http URL schemas.
    The webview only opens http, https.

I want to open over 50 URL schemes, what should I do?

CodePudding user response:

You can use SafariServices framework. The code would look like that if you call it from some view controller:

if let url = URL(string: "<your_url>") {
    let safariVC = SFSafariViewController(url: url)
    present(safariVC, animated: true, completion: nil)
}

CodePudding user response:

I read this article about the 50 schemes limitation you have mentioned.

https://book.hacktricks.xyz/mobile-pentesting/ios-pentesting/ios-custom-uri-handlers-deeplinks-custom-schemes

It says that you need to add the schemes only if you use canOpenURL (the system method that is called in order to check if the apps are installed on the device). So, maybe you can use another check instead of canOpenURL, and this way you don't need to add the schemes to info.plist

You can always check the Bool value that is passed to the completion handler of UIApplication.shared.open(...) in order to tell if the other app was opened or not.

  • Related