Closed. This question needs to be more focused。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?更新问题,使其仅通过editing this post专注于一个问题。
                        
                        5年前关闭。
                                                                                            
                
        
我想做的是一个iOS应用新闻,其中显示图片和一些描述图片的文字。就像带有图像的“ 9GAG”和下面描述该图像的一些文字一样。每当出现新新闻时,此应用都必须更新内容。当用户单击图像时,会出现新闻的一段。如何使应用程序每天更新,而无需用户重新下载或手动更新应用程序?我真的不知道该怎么做,我必须连接到数据库还是网站?请帮忙!

非常感谢你。

最佳答案

在您的应用程序委托中,创建一个属性以保存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/

10-11 22:14
查看更多