<分区>
我想要做的是一个 iOS 应用程序新闻,它显示图像和一些描述图像的文本。就像“9GAG”一样,它有一张图片和下面的一些描述图片的文字。每次出现新消息时,此应用程序都必须更新内容。并且当用户点击图像时会出现一段新闻。如何让应用程序每天更新,而无需用户重新下载或手动更新应用程序?我真的不知道该怎么做,我必须连接到数据库或网站吗?请帮忙!
非常感谢。
最佳答案
在你的 App Delegate 中,创建一个属性来保存一个 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
}
}];
}
关于ios - 如何创建每日更新的 iOS 应用程序新闻,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21948968/