2013-01-09 3 views
2

수신 한 알림에 UIWebView로 열리는 URL이 있습니다. 하지만 내 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 수신 알림을 게시하는 것입니다. NSNotificationCenter Class Reference 또는 this example on SO을 확인하십시오. UIWebView가 화면에 이미 때 나는 다음을 사용하고 내 응용 프로그램에서

+0

감사합니다. 시도해 보겠습니다. :) –

1

이는 다음과 같습니다

- (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와 구조는 복잡한 것처럼 보이지만 이것은 내가 설정 한 방법을 필요했던 내 앱. 앱에서 다를 수 있습니다.

아이디어는 열린 viewcontroller를 가져 와서 UIWebView에 URL을로드하는 것입니다. 코드는 UIViewController이고 UIWebView은 현재 열려 있습니다. UIWebView에있는 URL을 열기 전에 올바른 UIViewController로 이동하려면 코드를 변경해야합니다.

0

장소의 UIWebView 같은있는 뷰 관찰자 :

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

가있는 UIWebView의 타겟 URL을 변경 recievedNotification 함수 내의 적절한 코드를 작성한다.

과 같은 APP 위임에 didReceiveRemoteNotification 기능에 알림을 게시 :

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

행운을 빕니다.

관련 문제