Today App Extension Widget Click to open Contains application

I applied the Today widget to my application + Quotes, which displays the quote of the day in the notification center using these Apple Docs . What I would like to do is to open the Containing App, in this case + Quotes, when the user throws the + Quotes widget into their Today notification type, I’m not quite sure what to call it, since Calendar will be if you click its in today’s look. I tried overlaying a button over a shortcut that would call -(void)openURL:(NSURL *)URL completionHandler:(void (^)(BOOL success))completionHandler after it listens, open the custom URL scheme that I declared to open the Containing application. The problem is that it does not open the Containing App.

+ Quotes Today App Extension Widget

 -(IBAction)myButton:(id)sender { NSURL *customURL = [NSURL URLWithString:@"PositiveQuotes://"]; [self openURL:customURL completionHandler:nil]; } 
+48
ios ios8 ios-app-extension today-extension
Jun 03 '14 at 16:04
source share
5 answers

EDIT: Okay, here is a little correction. I got it working with placing a button above the shortcut, as suggested above, and with the following code:

 - (IBAction) goToApp: (id)sender { NSURL *url = [NSURL URLWithString:@"floblog://"]; [self.extensionContext openURL:url completionHandler:nil]; } 

I associated it with the Touch Up Inside event. However, this also leads to the launch of the application when the user views the Today view.

=========================================

I ran into the same problem. However, there seems to be no solution at the moment, as release notes for the first beta of iOS 8 are mentioned:

Known issues: openURL does not work with the extension.

So, I think we have to wait until beta 2.

+59
Jun 04 '14 at 13:25
source share

Swift 2 version according to Apple Doc

 extensionContext?.openURL(NSURL(string: "foo://")!, completionHandler: nil) 

version of Swift 3

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

And don't forget to add custom URL schemes in Info.plist

enter image description here

+38
Aug 24 '15 at 17:07
source share

The answer from @sunseeker is good, but it is "hidden" in the comments. And since the accepted answer says this is not possible, this can be misleading to visitors.

this code works:

 - (IBAction)launchHostingApp:(id)sender { NSURL *pjURL = [NSURL URLWithString:@"hostingapp://home"]; [self.extensionContext openURL:pjURL completionHandler:nil]; } 

I am using Xcode 6.0 (6A215l) with Yosemite Beta 1.

And as Apple says in "Community Use Scenarios":

The extension does not directly report the opening of the application containing it; instead, it uses the openURL: completeHandler: NSExtensionContext method to tell the system to open its containing application. when an extension uses this method to open a URL, the system checks the request before executing it.

+27
Jun 14
source share

Another way to do this without adding a hidden button is to add a UITapGestureRecognizer to the UILabel (be sure to set userInteractionEnabled to true on the label). Check the status of the resolver in the handler to make sure that you have reached UIGestureReconizerStateEnded (and not canceled or worked), and then run your openUrl code.

+1
Jun 17 '14 at 18:55
source share

Just in case, here is the version for Swift 3 with the error handling version:

 let myAppUrl = URL(string: "main-screen:")! extensionContext?.open(myAppUrl, completionHandler: { (success) in if (!success) { print("error: failed to open app from Today Extension") } }) 

To make it work, you need to open Application info.plist (open as source) and at the very top, after that

 <?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> 

add the following, so the application will know which URLs it should handle. Here is a complete example on how to open the containing application and share the default settings between the application and the extension.

+1
Feb 16 '17 at 5:29
source share



All Articles