简体   繁体   English

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

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

I am using Today extension in ios. 我在ios中使用Today扩展。

I have multiple view controller with different info. 我有多个具有不同信息的视图控制器。 and I am displaying some info in tableview using Today extension. 并且我正在使用Today扩展在tableview中显示一些信息。 when click on row then I want to open related viewcontroller with info. 当点击行,然后我想打开相关的viewcontroller与信息。

I have tried following code. 我试过下面的代码。

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

   }

I have set url schemes in info.plist 我已经在info.plist中设置了网址方案

but using this code I can only open root viewcontroller. 但是使用此代码,我只能打开root viewcontroller。

appreciate for help. 感谢您的帮助。

Yes you can open the customViewController progrmattically by passing custom data to urlSchemes. 是的,您可以通过将自定义数据传递给urlSchemes来以编程方式打开customViewController。

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

Implement the delegate method and get the string from url and than push the customViewController progrmattically. 实现委托方法并从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