Can't open host application from today's extension

I added a button to my app widget. After reading some tutorials and SO tips, I implemented what they wrote, but my action does not open the host application. Here's how I did in the Info.plist of the host application

And I made the url id as complete as the bundle id (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 compiled and did not fail, but completeHandler always returns "false" for "success". What did I do wrong and how do I get it right?

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

+3


source to share


1 answer


To open the host application from the Today Extension :

1.Add URL Scheme

: localHost

to host the application URL Types

.

enter image description here



2. Copy 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)")})
    }
}

      

+5


source







All Articles