Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

ios - Today App Extension Widget Tap To Open Containing App

I've implemented a Today widget for my application +Quotes which displays the day's quote within the notification center with the help of these Apple Docs. What I'd like to accomplish is opening the Containing App, in this case +Quotes, when the user taps the +Quotes widget within their Today notification view, not entirely sure what to call this, as Calendar would if you tapped it in the Today view. I've tried overlaying a button over the label which would call -(void)openURL:(NSURL *)URL completionHandler:(void (^)(BOOL success))completionHandler upon it being tapped, then open the Custom URL Scheme I have declared to open the Containing App. The issue is it doesn't open the Containing App.

+Quotes Today App Extension Widget

-(IBAction)myButton:(id)sender {
    NSURL *customURL = [NSURL URLWithString:@"PositiveQuotes://"];
    [self openURL:customURL completionHandler:nil];
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

EDIT: Ok, just a little correction here. I got it working with placing a button over the label just like suggested above and the following code:

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

I linked it to a "Touch Up Inside" event. However, this also causes the app to launch when the user scrolls the Today view.

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

I ran into the same issue. However, it seems that there is no solution for now since the release notes for the first beta of iOS 8 mention:

Known Issues: openURL does not work from an extension.

So I guess we will at least have to wait until beta 2.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...