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?
Asked
Active
Viewed 5,448 times
6
-
1Please take a look at this http://stackoverflow.com/questions/24019820/today-app-extension-widget-tap-to-open-containing-app – JulianM Aug 14 '15 at 20:40
2 Answers
11
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.

Christopher Pickslay
- 17,523
- 6
- 79
- 92
-
Since you said you want it to launch when the user taps a UITableViewCell, presumably you'd call it in `tableView:didSelectRowAtIndexPath:` – Christopher Pickslay Aug 15 '15 at 17:41
-
I tried this already but the func `tableView:didSelectRowAtIndexPath` isn't working. – paro Aug 15 '15 at 18:22
-
I tried this already but the func `tableView:didSelectRowAtIndexPath` isn't working. – paro Aug 15 '15 at 18:26
-
There is a bug where tapping blank areas in `UITableViewCell`s does not result in table view callbacks. Take a look at http://stackoverflow.com/questions/26223537. – Christopher Pickslay Aug 16 '15 at 20:38
-
2
The provided code by Christopher Pickslay works fine, you just need to add the following lines to the application's info.plist (open as a source code):
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.mikitamanko.myapp</string>
<key>CFBundleURLSchemes</key>
<array>
<string>some-context</string>
</array>
</dict>
</array>
right after the
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
Here's the complete guide how to open the app or share Users Defaults with Extension and the containing app.

Mikita Manko
- 1,133
- 9
- 9