ios - 推送通知后从 URL 方案打开 UIViewController

标签 ios uiviewcontroller uinavigationcontroller push-notification url-scheme

我想根据从 URL 方案获得的 id 打开特定的 UIViewController。

例如 myapp://news/285 将打开显示此特定新闻的 UIViewController“新闻”。

我在这里收到通知:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)source
         annotation:(id)annotation
{   
    if ([[url scheme] isEqualToString:@"myapp"]) {

        NSString *urlString = url.absoluteString;

...

        return YES;
    }

    return NO;
}

但是我应该如何推送 UIViewController ?我无法从这里访问导航 Controller 。

(我正在考虑使用 NSNotficationCenter 向我的主页发送带有 id 的通知,然后从那里推送 UIViewController。你觉得怎么样?)

谢谢

最佳答案

您知道您查看设置。因此,当您的 rootViewController 是 UINavigationController 时,您可以使用:

UINavigationController *navCon = (UINavigationController*)self.window.rootViewController;
[navCon pushViewController:myPushedVC animated:NO];

如果没有,那么也许使用通知方法会更容易

关于ios - 推送通知后从 URL 方案打开 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20548591/

相关文章:

ios - 什么是 AuthStateDidChangeListenerHandle?

iOS SDL2 OpenGL ES 无法绘制纹理

ios - 为什么旋转在 iOS 6 上工作时对 iOS 5 不起作用

iphone - UIView autoresizingmask 不适合我

ios - 导航栏后退按钮未显示?

ios - 如何向 uiTableView Controller 添加滑动和标题 View 。?

ios - 使属于 UIView 子类的计时器无效

ios - 新的 View Controller 出现然后消失在 CCScene 后面

ios - UINavigationController 中的 UITableController 返回到上一个 View / Controller

ios - 找不到导航 Controller 来导航另一个 View Controller