Tuesday, September 25, 2018

Opening Containing app from Today extension

self.extensionContext?.open(URL(string: "appscheme://")!, completionHandler: nil)

In the containing app, the scheme needs to be defined.

Also in the app delegate, below to be implemented as well

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool
    {
        if url.scheme == "appscheme"
        {
// navigate to appropriate areas in the app.     
        }
        return true
    }

Even without having the above method implemented, it will launch the app. However, it won't be able to navigate to specific areas until the code is in place for it.

Implementation wise, one can just have the button on the today widget main interface.storyboard file and link it to the TodayViewController and handle the actions via IBaction outlets. It is pretty easy.

references:
https://hackernoon.com/app-extensions-and-today-extensions-widget-in-ios-10-e2d9fd9957a8

No comments:

Post a Comment