2014-02-22 216 views
0

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

非常感谢。

+0

取决于您是否连接到第三方提供商以获取此新闻。如果您自己手动控制此新闻,那么托管提供商(如Amazon S3)上的简单属性列表就可以完美实现。 – klcjr89

+0

当然,我要控制这个消息。当我想发布新消息时,我的应用必须更新。我怎么做? – manunez19

+0

通过更新,您的意思是向用户发送推送通知,并让他们决定是否打开应用程序,或者每次应用程序进入前台时进行更新。 – klcjr89

回答

1

定期刷新您的应用程序在应用程序委托中,创建一个属性来保存一个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 
     } 
    }]; 
} 
+0

我应该在哪里找到我想要在我的应用上发布的图片和新闻? – manunez19

+0

UITableView是显示这种类型内容的最佳方式之一,它甚至可以让你在不需要特殊工作的情况下进行刷新。 – klcjr89

+0

但是从哪里我应该上传我的图像?从数据库?服务器? – manunez19

0

如何增加计时器,并在特定timeinerval

相关问题