0

我正在寻找一种能够在 iPhone 应用程序中处理定期维护的方法。我们在我们的应用程序中使用 Web 服务(.Net/C#),最近我们增加了服务器数量来维护网站上的流量。因此,每当网络团队上传网站时,他们都会显示网站正在进行定期维护。对于 iPhone,我编写了下面的代码来同时处理超时。

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];

它将在 60.0 秒后通知用户。所以用户抱怨冻结iPhone 应用程序。有没有其他方法来处理这个?或者有没有其他方法可以在定期维护时打开任何特定屏幕?

任何帮助将不胜感激!谢谢。

4

2 回答 2

1

您需要在单独的线程上执行此代码。最简单的方法是使用 Grand Central Dispatch,如下所示:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{

    NSURLResponse *response = nil;
    NSError *error = nil;
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];
    NSData *resultData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];

    // Add code to handle returningResponse.

    // Error handling
    if (error != nil) {
        NSLog(@"An error occured! %@", error);
    }
});
于 2013-03-09T06:07:02.377 回答
1

在这种情况下,iOS 7 静默后台通知可能适合您。

于 2014-09-18T21:46:30.480 回答