无需用户交互即可有效自动刷新UITableview(IOS 5) [英] Effective automatic refresh of UITableview without user interaction (IOS 5)

查看:78
本文介绍了无需用户交互即可有效自动刷新UITableview(IOS 5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从未使用推送通知编写应用程序,我有一个非常笼统的问题。
我想自动刷新UITableview的数据(来自网络服务)而没有拉动刷新或任何其他用户的互动。是否可以使用推送通知来通知我的应用程序数据更改,以避免每xx秒轮询浪费带宽和电池?

I have never coded an App with Push Notifications and I have a very general question. I would like to refresh a UITableview's data (coming from a webservice) automaticaly without "pull to refresh" or any other user's interaction. Is it possible to use Push notifications to inform my app for a data change, in order to avoid polling every xx seconds wasting bandwidth and battery?

换句话说,虽然我的应用程序在前台运行(也许)我可以处理消息,用户不会收到弹出窗口但是会发生什么呢?

In other words, while my app runs in the foreground (maybe) I can handle the message and the user wont receive a popup but what happens otherwise?

还有其他方法可以实现相同的结果?

Is there any other way to achieve the same result?

我打算使用IOS 5.0+

I am going to use IOS 5.0+

提前致谢

推荐答案

您可以创建一个服务器HTTP-Request,只有在发生更改时才会返回。然后,如果此响应不为空,您可以重新加载数据。您可以通过NSTimer调用的函数。

You could make a server HTTP-Request which only returns something if there was a change. Then in case this response is not empty you can reload the data. The function you can call by a 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
    }
}

这篇关于无需用户交互即可有效自动刷新UITableview(IOS 5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆