繁体   English   中英

点击扩展程序(今天的扩展程序)后是否可以打开特定的viewcontroller(包含应用程序)?

[英]is it possible to open specific viewcontroller(containing app) after tap on extension(today extension)?

我在ios中使用Today扩展。

我有多个具有不同信息的视图控制器。 并且我正在使用Today扩展在tableview中显示一些信息。 当点击行,然后我想打开相关的viewcontroller与信息。

我试过下面的代码。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
   {
      NSURL *url = [NSURL URLWithString:@"ReadText://"];
      [self.extensionContext openURL:url completionHandler:nil];

   }

我已经在info.plist中设置了网址方案

但是使用此代码,我只能打开root viewcontroller。

感谢您的帮助。

是的,您可以通过将自定义数据传递给urlSchemes来以编程方式打开customViewController。

NSURL *url = [NSURL URLWithString:@"ReadText://customViewController"];

实现委托方法并从url获取字符串,然后以customViewController方式推送customViewController。

 -(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
       NSString *viewController =  [[url host] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
       if([viewController isEqualToString:@"customViewController"]) {
          //push customViewController on rootViewController
       }
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM