2013-01-09 26 views
2

我收到的通知中包含一個要在UIWebView中打開的網址。但我無法從我的AppDelegate訪問UIWebview(這是收到notification的地方)。收到通知後,我想更改我的uiwebview

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

回答

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上加載一個URL。代碼假設UIViewControllerUIWebView當前處於打開狀態。如果您想在UIWebView中打開網址之前導航到正確的UIViewController,則應該更改代碼。

0

地方觀察者其中的UIWebView駐留如視圖:

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

收件recievedNotification功能,其改變的UIWebView的目標URL內的適當的代碼。

而且在應用程序委託張貼在didReceiveRemoteNotification功能的通知,如:

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

好運。

相關問題