Skip to content

Instantly share code, notes, and snippets.

@erkekin
Created February 9, 2017 08:17
Show Gist options
  • Select an option

  • Save erkekin/35a417cb476cfe750596884ef7349186 to your computer and use it in GitHub Desktop.

Select an option

Save erkekin/35a417cb476cfe750596884ef7349186 to your computer and use it in GitHub Desktop.
func getURLSchema() -> String?{
guard let schemas = Bundle.main.object(forInfoDictionaryKey: "CFBundleURLTypes") as? [[String:Any]],
let schema = schemas.first,
let urlschema = schema["CFBundleURLName"] as? String
else {return nil}
return urlschema
}
@Ayyyyybeeeee
Copy link

This does not get the url scheme, it gets the url identifier (often called the url name).

Here is some simple code to get the scheme:

    func getURLSchema() -> String{

        guard let schemas = Bundle.main.object(forInfoDictionaryKey: "CFBundleURLTypes") as? [[String:Any]],
            let schema = schemas.first,
            let urlschemas = schema["CFBundleURLSchemes"] as? [String]
        else {return "nil"}

        guard let urlschema = urlschemas.first
        else {return "nil"}

        return urlschema

    }

@erkekin
Copy link
Author

erkekin commented Dec 31, 2025

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment