5

We have our app target, and in that Info.plist, we defined URL Schemes that can be used to open the app with a URL.

Now we are adding a today extension. We will want to have a table view who will open that URL from the extension. We see how that is supported in the API.

Can we get the URL scheme from the app's Info.plist, or are we basically "hard coding" the value in the extension for it to call to open?

Jason Hocker
  • 6,879
  • 9
  • 46
  • 79

2 Answers2

2

To get infos.plist values you can use this:

let urlTypesArray = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleURLTypes")

You can find the right key (CFBundleURLTypes) opening the info.plist as Source Code (right click)

then, find the value :

let urlSchemesValue = urlTypesArray![0]["CFBundleURLSchemes"]
print("urlSchemesValue => \(urlSchemesValue)") 
Damien Romito
  • 9,801
  • 13
  • 66
  • 84
2

The answer by @damien is not correct. That will only return the Extension Info.plist file.

The correct answer can be found here in another SO post.

MobileVet
  • 2,958
  • 2
  • 26
  • 42