2

我收到的通知包含一个要在UIWebView. 但我无法UIWebview从我的AppDelegate(这是接收的地方notification)访问。

-(void) application:(UIApplication *)application didReceiveRemoteNotification(NSDictionary* ) userInfo{
      // handle notification (this works)
      //HERE I want to call my UIWebView and load the url I got.
}
4

3 回答 3

1

在我的应用程序中,我使用了以下内容,这是UIWebView屏幕上已经出现的情况:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    NSString *urlString = [userInfo objectForKey:@"url"];
    if( [self.window.rootViewController isKindOfClass:[UINavigationController class]] ){
        UINavigationController *currentNavigationController = (UINavigationController*)self.window.rootViewController;
        if( [currentNavigationController.visibleViewController isKindOfClass:[NHCallVC class]] ){
            SomeViewController *currentViewController = (SomeViewController*)currentNavigationController.visibleViewController;
            [currentViewController.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
        }
    }
}

的结构UINavigationController看起来很复杂,但这是我设置应用程序的方式所需要的。这在您的应用程序中可能会有所不同。

这个想法是获取打开的视图控制器并在UIWebView. 代码假设UIViewController当前UIWebView是打开的。如果您想UIViewController在打开UIWebView.

于 2013-01-09T09:03:22.943 回答
1

一种方法是发布您UIWebView收到的通知。查看NSNotificationCenter 类参考SO 上的这个示例

于 2013-01-09T09:00:45.073 回答
0

将观察者放置在 UIWebView 所在的视图上,例如:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recievedNotification:) name:@"ReceivedNotification" object:nil];

在 recievedNotification 函数中编写适当的代码来更改 UIWebView 的目标 url。

并在 APP Delegate 中的 didReceiveRemoteNotification 函数中发布通知,例如:

    [[NSNotificationCenter defaultCenter] postNotificationName:@"ReceivedNotification" object:nil];

祝你好运。

于 2013-01-09T09:05:50.253 回答