从服务器下载plist [英] Download plist from server

查看:89
本文介绍了从服务器下载plist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我有一个读取plist网站的应用程序,但是它会像这样工作吗:

Today I have an application that reads a plist site, but would it work like this:

打开应用程序时,它将检查用户是否已在设备上拥有plist,以及该plist是否为最新版本.

when you open the app it checks if the User already has the plist on device and if that is the latest version.

如果没有,则为服务器捕获的最新版本

If you have not or not it is the latest version of the server catches

http://lab.vpgroup.com.br/aplicativos/teste-catalogo/lista.plist

我该怎么做? 我在这里看到了很多关于stackoverflow的问题,但是没有一个能满足我的需要.

How could I do this? I have seen many questions here on stackoverflow, but none worked as I need.

谢谢

推荐答案

您永远不想阻止UI.下载可能需要很长时间.因此,请在后台执行.最简单的方法是使用NSURLConnection的便捷方法sendAsynchronousRequest:request,顾名思义,它是异步的,并在下载完成后调用传递的完成块

you never want to block the UI. Downloading can take a long time. Therefore do it in background. Easiest is using NSURLConnection's convenience method sendAsynchronousRequest:request Like the name says, it is asynchronous and calls the passed completion block when the download finished

NSURL *url = [NSURL URLWithString:@"http://lab.vpgroup.com.br/aplicativos/teste-catalogo/lista.plist"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
    NSDictionary *dict = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:0 format:0 errorDescription:nil];
    NSLog(@"%@", dict);
}]; 


示例:


Sample:

#import <Foundation/Foundation.h>

int main(int argc, char *argv[]) {
    @autoreleasepool {
            NSURL *url = [NSURL URLWithString:@"http://lab.vpgroup.com.br/aplicativos/teste-catalogo/lista.plist"];
            NSURLRequest *request = [NSURLRequest requestWithURL:url];
            [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
               NSDictionary *dict = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:0 format:0 errorDescription:nil];
               NSLog(@"%@", dict);
            }]; 

            //just for demo
            [[NSRunLoop currentRunLoop] run];
    }
}

这篇关于从服务器下载plist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆