你可以做一個服務器的HTTP請求,只有當出現了一個變化返回的東西。那麼如果這個響應不是空的,你可以重新加載數據。您可以通過NSTimer調用的函數。
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(get) userInfo:nil repeats:YES];
和
-(void)get {
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com/app.php"]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if(![responseString isEqualToString:@""]) {
// reload
}
}
或與'didReceiveLocalNotification'結合(由斯蒂芬達林頓回答上面) – Dion 2012-04-10 12:04:23
謝謝!這有很大幫助。不幸的是我無法投票,因爲我沒有15點聲望點! – vassilag 2012-04-10 12:05:50
你說你想避免輪詢!僅僅因爲身體中沒有數據並不意味着無線電已關閉或沒有數據傳輸。 – 2012-04-10 12:24:17