swiftuitableviewxcode6ios8-today-widgettoday-extension

Open main app via today extension


I implemented added a today widget into my app. The today extension includes an UITableView. Now I'd like to open the app if a cell of the UITableView has been pressed. Does someone of you know how to do this?


Solution

  • Today extensions have access to an NSExtensionContext which allows you to open an app. In your extension controller:

    let myAppUrl = NSURL(string: "myapp://some-context")!
    extensionContext?.openURL(myAppUrl, completionHandler: { (success) in
        if (!success) {
            // let the user know it failed
        }
    })
    

    The success parameter is provided because the system may not be able to open a particular URL (say you want to launch "twitter://" but the user does not have the Twitter app installed. If you're launching your own app, this shouldn't be an issue.