I have a Today Extension with a text field. I want to use the contents of the text field as a URL to open a browser within my app.
This is my TodayViewController.swi
You could use @Giuseppe_Lanza solution and parse url that you receive from Today Extension Widget. However, I would show an example where your url have a static components and looking for a path such as https:/www.apple.com/homepod
or https:/www.apple.com/iphone
based on user's input in the textField:
1- URL Scheme: myAppName
2- Add this to open your app with widget
@IBAction func goButton(_ sender: Any) {
openApp(widgetText: "\(textBox.text!)")
}
func openApp(widgetText:String) {
let str = "myAppName://https://www.apple.com/\(widgetText)"
let url = URL(string: str)!
if textBox.hasText == true {
extensionContext?.open(url, completionHandler: { (success) in
if (!success) {
print("error: