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

标签 ios iphone ipad

<分区>


想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post .

关闭 9 年前

我想要做的是一个 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/

上一篇:ios - 在 facebook 中出现此错误 (com.facebook.error.2 )

下一篇:ios - animateWithDuration 根本没有运行

相关文章:

iphone - 通过 XML 从 iPhone 向 App Engine 发送图像

iphone - 自动更改到下一个 ViewController

iphone - 如何设置渐变 UITableViewCell 背景?

iphone - 试图了解iOS平台上的内存管理

ios - 如何将图像添加到 UIImageView?

ios - 弹出到 Root View Controller , TableView 没有动画崩溃

ios - 适用于 iOS 7 和 iOS 8 的警报

iphone - 绘制两个CGMutablePath Ref的问题

iphone:界面更改时搜索栏删除背景

ios - 当用户点击 View 外的任何地方时关闭 View