2014-09-20 57 views
0

有什麼方法可以在新通知到達時刷新或重新加載UIWebView?iOS如何在didReceiveRemoteNotification上刷新UIWebView

我一直在試圖尋找答案,但沒有到目前爲止。

有人知道這一點,請幫助我。

感謝

我嘗試如下,但沒有...

在AppDelegate.m

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 


    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(reloadWebView:) 
               name:@"PUSH_NOTIFICATION" object:nil]; 
} 

而在MainViewController.m

-(void)receivedNotification:(NSNotification*) notification 
{ 
[_webView reload]; 
} 

-(void)dealloc 
{ 
[[NSNotificationCenter defaultCenter] removeObserver:self]; 
} 

我把下面的代碼相當新手...

回答

0

我解決...

我的情況是刷新網頁視圖時,新的推送通知到達。

在AppDelegate.m

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 

    [[NSNotificationCenter defaultCenter] postNotificationName:@"reloadWebView" object:nil]; 
} 

而且在ViewController.m

- (void)viewDidLoad 
{ 
[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(reloadWebView:) 
              name:@"reloadWebView" object:nil]; 
} 

-(void)viewDidUnload 
{ 
[self unregisterForNotifications]; 
} 

-(void)reloadWebView:(NSNotification*) notification 
{ 
[_webView reload]; 
} 

-(void)unregisterForNotifications 
{ 
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"reloadWebView" object:nil]; 
} 

效果很好。

0

要刷新UIWebView,您可以在實例上調用reload。不過,我認爲你知道這一點,並需要一種方法來稱呼它通知到達。我會建議使用廣播機制在這裏: - 把它當遠程通知到達 - 登記擁有的註冊選擇Web視圖&刷新Web視圖

你可以找到信息如何在衆多的教程使用廣播視圖控制器廣播處理器,例如這一個http://hayageek.com/nsnotification-nsnotificationcenter-tutorial/