从后台加载url中的一个大plist [英] Load a big plist from url in background

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

问题描述

我从url加载了一个很大的plist文件,必须等待几秒钟才能使用该应用程序.有什么解决办法吗?如何在后台加载?我需要GCD吗?如何实现?

I load a big plist file from url and I must wait for some seconds before I can use the application. Is there some solution? How it can be loaded in background? Is GCD what I need? How it can be implemented?

我的代码:

NSString *urlStr = [[NSString alloc] 
                    initWithFormat:@"http://www.domain.com/data.xml"];

NSURL *url = [NSURL URLWithString:urlStr];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfURL:url];

推荐答案

您可以创建一个新线程来这样做 请检查以下内容

You could create a new thread to do so Please check the following

//Create the thread 
[NSThread detachNewThreadSelector:@selector(loadPList) toTarget:self withObject:nil];

- (void) loadPList
{
    //Load the plist
    NSString *urlStr = [[NSString alloc] 
                       initWithFormat:@"http://www.domain.com/data.xml"];

    NSURL *url = [NSURL URLWithString:urlStr];
    NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfURL:url];

    //Update the ui
    dispatch_async(dispatch_get_main_queue(), ^{
        //Update UI if you have to
    });

}

这篇关于从后台加载url中的一个大plist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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