如何创建每日更新的iOS应用程序新闻

时间:2014-02-22 02:48:54

标签: ios iphone ipad

我想要做的是iOS应用新闻,它会显示图像和一些描述图像的文字。就像'9GAG'有一个图像和下面的一些文字描述图像。每次出现新消息时,此应用都必须更新内容。而当用户点击图片时会出现一段新闻。如何在不让用户重新下载或手动更新应用的情况下让应用程序每天更新?我真的不知道该怎么做,我是否必须连接到数据库或网站?请帮忙!

非常感谢。

2 个答案:

答案 0 :(得分:1)

在你的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
         }
     }];
}

答案 1 :(得分:0)

如何在特定的时间段定期添加计时器和刷新应用

相关问题