我为我的包含应用程序设置了Today Extension。从Today窗口调用openURL会打开应用程序,但不会调用应用程序:openURL:sourceApplication:注释:
下面是代码:
TodayViewController:
[self.extensionContext openURL:[NSURL URLWithString:[NSString stringWithFormat:@"idaxiang://action=%ld",(long)aCell.tag]] completionHandler:^(BOOL success) {
NSLog(@"open url result:%d",success);}];
AppDelegate.m:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
NSString* prefix = @"idaxiang://action=";
if ([ElephantUtils originString:[url absoluteString] withTargetString:prefix]) {
if ([[url absoluteString] rangeOfString:prefix].location != NSNotFound) {
NSString* action = [[url absoluteString] substringFromIndex:prefix.length];
UINavigationController *navc = (UINavigationController *)application.keyWindow.rootViewController;
if (navc.viewControllers.count > 1) {
[navc popToRootViewControllerAnimated:NO];
}
ElephantHomeViewController *homeVC = (ElephantHomeViewController *)navc.topViewController;
[homeVC PushToSpecificArticle:[action integerValue]];
}
return [[Diplomat sharedInstance] handleOpenURL:url];
}
但奇怪的是,如果包含应用程序无法打开(不加载到内存),我点击Today Extension中的单元格,应用程序将打开,但不能拨打application:openURL:sourceApplication:annotation:
,因此它不会推送到目标视图控制器。但现在,应用程序已打开(已加载到内存),我点击Today Extension中的单元格,包含的应用程序将调用application:openURL:sourceApplication:annotation:
并成功推送到目标视图控制器。
这里是我的info.plist:
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>com.smartisanelephant.www</string>
<key>CFBundleURLSchemes</key>
<array>
<string>idaxiang</string>
</array>
</dict>
请给我一些建议,我一直在努力这个问题了一些日子。非常感谢!
'application:openURL:sourceApplication:annotation:'should should be called when you launch your app via a URL scheme。你确定它没有被调用?也许你的URL解析代码中有一个错误? –