使用UIStoryBoard处理基于“自定义URL方案”的屏幕

Praveenkumar

我有两个名为的应用程序,

  1. SendDataApp
  2. ReceiveDataApp

这是我的ReceiveDataApp的StoryBoard

ReceiveDataApp故事板

我可以将数据发送到接收应用程序,并可以通过以下方法进行处理,

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options;

但是,这里的问题是我想将我从SendDataApp接收的数据显示给我正在尝试使用以下方法来处理DetailViewControllerReceivedDataApp

Appdelegate.m

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    ViewController *viewController = (ViewController *)[storyBoard instantiateViewControllerWithIdentifier:@"View"];
    [viewController receivedURL:url];
    return YES;
}

ViewController.m

- (void)receivedURL:(NSURL *)url {
    [self performSegueWithIdentifier:@"detailIdentifier" sender:url];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"detailIdentifier"]) {
        DetailViewController *detail = [segue destinationViewController];
        detail.receivingURL = (NSURL *)sender;
    }
}

但是,这给了我一些错误

Terminating app due to uncaught exception 'NSGenericException', reason: 'Could not find a navigation controller for segue 'detailIdentifier'. Push segues can only be used when the source controller is managed by an instance of UINavigationController.

My two viewcontrollers embedded in UINavigationController only. And, normally i can view detail page by button action. But, not by URL Scheme

What was the mistake here? And, am i doing anything wrong here?

Give me some suggestions or idea to handle this.

Michael Dautermann

You instantiate your ViewController in your AppDelegate's openURL method and ARC immediately releases the view controller when that openURL method returns. It doesn't survive long enough to be added to the navigation controller

您真正需要做的是获取当前显示的视图控制器(可能是您的“ View Controller,也可能不是您的“ ”),然后执行此操作。

换句话说,在您的应用程序委托中:

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {

    UIViewController *rootvc = self.window.rootViewController;

    // make sure the root view controller is the ViewController class you want
    if ([rootvc isKindOfClass: [ViewController class]])
    {
        ViewController * vc = (ViewController *)rootvc;
        [vc receivedURL:url];
    }
    return YES;
}

您可以在此问题此问题中看到更多我正在尝试使用答案做的事情

最后,您确实必须重命名子类化的视图控制器,使其名称与超级通用的“视图控制器”和“详细信息视图控制器”名称不同。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用RoutablePageMixin基于的Wagtail自定义URL

使用CEFPython为Chromium嵌入式框架定义自定义方案处理程序

如果未处理Android自定义URL方案,如何退回到市场?

React Native:这不是处理自定义URL方案的函数

处理滥用自定义URL方案以进行网络钓鱼攻击ios的最佳做法

如何在 Xamarin Forms 中处理自定义 URL 方案

使用@DataJpaTest设置自定义方案

UriComponentsBuilder使用自定义方案截断

定义iOS应用的SSL自定义URL方案

android基于回合的多人自定义邀请屏幕

自定义URL处理iOS xamarin

无法使用自定义URI方案从URL打开Tha应用

在Cordova中将handleOpenURL与自定义URL方案一起使用

自定义URL方案如何与iOS7中的“ UILaunchImages”键一起使用?

为允许的方案打开审核URL。允许使用“文件:”或自定义方案通常是意外的

以http开头的自定义URL方案不起作用

自定义URI方案“不受支持的URL”

将参数从自定义URL方案传递到Webview

Cordova 自定义 URL 方案插件不起作用

xcassets和自定义URL方案启动图像

iOS 10上的设置的自定义URL方案?

基于自定义参数的快速路由处理程序

Workbox - 使用自定义处理程序

使用自定义消息处理错误?

无法在XCTest中从UIStoryboard投射自定义UIViewController

基于Django类的视图。对不同的URL使用相同的自定义类

WKWebView不打开自定义URL方案(js在新窗口中打开自定义方案链接)

使用RegEx从文本中提取带有和不带有自定义URL方案的URL

在Vim中使用自定义颜色方案