我想要做的是iOS应用程序新闻,它显示图像和描述图像的一些文本。就像'9GAG'有一张图片和一些描述图片的文字。每次出现新消息时,此应用都必须更新内容。而当用户点击图片时会出现一段新闻。如何让应用程序每日更新而无需用户重新下载或手动更新应用程序?我真的不知道该怎么做,我必须连接到数据库或网站吗?请帮忙!如何创建每天更新的iOS应用程序新闻
非常感谢。
我想要做的是iOS应用程序新闻,它显示图像和描述图像的一些文本。就像'9GAG'有一张图片和一些描述图片的文字。每次出现新消息时,此应用都必须更新内容。而当用户点击图片时会出现一段新闻。如何让应用程序每日更新而无需用户重新下载或手动更新应用程序?我真的不知道该怎么做,我必须连接到数据库或网站吗?请帮忙!如何创建每天更新的iOS应用程序新闻
非常感谢。
定期刷新您的应用程序在应用程序委托中,创建一个属性来保存一个NSDictionary以后可以访问你的应用程序的任何地方(例如一个UITableViewController)
AppDelegate.h:
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) NSDictionary *dictionary;
@end
AppDelegate.m:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://foobar.com/news.plist"]];
request.cachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData;
request.timeoutInterval = 5.0;
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:
^(NSURLResponse *response, NSData *data, NSError *error)
{
if (data)
{
NSPropertyListFormat format;
self.dictionary = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListImmutable format:&format error:nil];
// Todo: post an NSNotification to any other view controllers telling them that we have the new data.
}
else
{
// Tell user connection failed
}
}];
}
如何增加计时器,并在特定timeinerval
取决于您是否连接到第三方提供商以获取此新闻。如果您自己手动控制此新闻,那么托管提供商(如Amazon S3)上的简单属性列表就可以完美实现。 – klcjr89
当然,我要控制这个消息。当我想发布新消息时,我的应用必须更新。我怎么做? – manunez19
通过更新,您的意思是向用户发送推送通知,并让他们决定是否打开应用程序,或者每次应用程序进入前台时进行更新。 – klcjr89