Alexy Krivzov
Alexy Krivzov

Reputation: 105

Can't open host app from today extension

I've aded a button to my app widget. After reading some manuals and SO advises I've implemented what they wrote, but my action doesn't open host app. Here's how I made in Info.plist of host app

And I made URL identifier both completely like the bundle identifier (com.ol.MyList) and just com.ol. Both didn't work.

And here's my action:

@IBAction func openHostApp() {
    if let url = URL(string: "localHost") {
        self.extensionContext?.open(url, completionHandler: {success in print("called url complete handler: \(success)")})
    }
}

It's compiled and doesn't crash, but completionHandler always return 'false' for 'success' parameter. What I made wrong and how to make it right?

I also want to add another button that opens host app and performs an action in there. How to implement that case?

Upvotes: 3

Views: 1451

Answers (1)

PGDev
PGDev

Reputation: 24341

To open host app from Today Extension:

1.Add URL Scheme : localHost to host app's URL Types.

enter image description here

2.Code to open host app from extension,

   @IBAction func openHostApp()
{
    if let url = URL(string: "localHost://")
    {
        self.extensionContext?.open(url, completionHandler: {success in print("called url complete handler: \(success)")})
    }
}

Upvotes: 6

Related Questions