2013-04-06 1 views
0

UIWebView가있는 iPhone 앱이 있습니다. X 시간 후에 사용자가 앱을 다시 시작하면 페이지에 새로운 콘텐츠가 있어도 웹보기에 동일한 데이터가 표시됩니다. X 시간이 지난 후에 사용자가 앱을 다시 시작할 때 페이지를 새로 고치기 위해 UIWebView를 자동으로 얻으려면 어떻게해야합니까? 이 않는 X 시간을 카운트iPhone 용 UIWebview는 어떻게 새로 고 칩니 까?

- (NSTimeInterval)timeIntervalSinceDate:(NSDate *)anotherDate 

: 웹보기가 시간 차이를 계산하기 위해

[webView reload]; 

을 사용하여 다시로드

답변

2

이 추가가있는 viewDidLoad입니다 :

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationEnteredBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationEnteredForeground) name:UIApplicationDidEnterForegroundNotification object:nil]; 

쓰기 알림 기능을 처리하십시오.

-(void)applicationEnteredBackground 
{ 
    //storing timestamp when user goes background 
    NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults]; 
    [userDefaults setObject:[NSDate date] forKey:@"timeStamp"]; 
    [userDefaults synchronize];  
} 

-(void)applicationEnteredForeground 
{ 
    NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults]; 
    NSString *lastTimeOpened= [userDefaults objectForKey:@"timeStamp"]; 
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init]; 
    //set formatter style as long 
    if([[NSDate date] timeIntervalSinceDate:[formatter dateFromString:lastTimeOpened]] > X hours) 
    { 
    //reload your webview here. 
    } 
} 
+0

안녕하세요, 작은 논리 오류가있을 수 있지만이 방법은 저에게 맡겨주세요. – satheeshwaran

+1

@sharataka 작동 했습니까? 네가 그걸로 멋지다면 내 ans 투표를 수락하십시오. – satheeshwaran

관련 문제