主UI线程中的网络通信

时间:2012-12-01 12:38:47

标签: objective-c ios multithreading networking

我有以下关注......

我的应用程序第一次启动时会下载6 MB的数据。 在此过程中,会显示UIView,其中包含有关正在进行的下载的信息,并且通常不会与用户进行交互。

因此我使用dispatch_async在主UI线程中下载所有数据,但现在我不知道这是否是最佳解决方案以及Apple在提交申请时会说些什么。< / p>

如果这是好的,请指导我吗?

更新
发货代码

//Called at the end of [UIViewController viewDidLoad]
-(void)splashScreenAppeared
{
myTabBarController_.loadingLabel.text = NSLocalizedString(@"Checking for updates",@"launch progress");
dispatch_queue_t d_queue = dispatch_get_main_queue();
[self launchActionCheckIfDataIsStored:d_queue];
}
//...
-(void)launchActionCheckIfDataIsStored:(dispatch_queue_t)queue
{
dispatch_async(queue, ^ {
    //If there is no data stored in core data then download xml data files and images
    if (![self isAnyDataStoredInCoreData]) {
        launchNoDataStored_ = YES;
        [self launchDownloadData:queue];
    } else {
        launchNoDataStored_ = NO;
        [self launchCheckNewVersion:queue];
    }

});
}
//...
-(void)launchDownloadData:(dispatch_queue_t)queue
{        
myTabBarController_.loadingLabel.text = NSLocalizedString(@"Downloading catalog data",@"launch progress");
dispatch_async(queue, ^ {
    [self loadMenuData];
    if (seriousError_) {
        [self launchSeriousError:queue];
        return;
    }

    myTabBarController_.loadingLabel.text = NSLocalizedString(@"Downloading products details",@"launch progress");
    dispatch_async(queue, ^ {
        [self loadProductsData];
        if (seriousError_) {
            [self launchSeriousError:queue];
            return;
        }
//...
//And so on with other parts of download
}

2 个答案:

答案 0 :(得分:0)

为了设置背景,我写了&amp;向App Store提交了2个成功的应用程序,因此您知道我不是在假设。

回来后,您可以将下载推送到后台线程,并以滑块的形式更新进度(为了用户的利益)。但是,如果在这种情况下用户无论如何都无法做任何事情那么就没有意义了。

另外,我不认为Apple会拒绝你的应用程序。他们检查的主要内容之一是,如果您使用任何私有API或更基本的应用程序崩溃。所以请继续提交APP商店评论......

答案 1 :(得分:0)

现在我知道UI线程中的网络通信可能是Apple拒绝您的应用程序的一个很好的理由。

考虑以下情况:

  • 适用于iPhone。
  • 没有与用户互动。
  • 应用程序在iPad上运行!!

即使没有与用户交互,当用户在iPad上按 2x 按钮时,应用程序也不会做出反应。

因此,UI线程中的网络通信可以正常工作,但如果应用程序不仅适用于iPad,那么应用程序将在Apple审核过程中被拒绝。