Ios iPhone锁定时网络连接失败

Ios iPhone锁定时网络连接失败,ios,iphone,error-handling,network-connection,Ios,Iphone,Error Handling,Network Connection,我开发了一个应用程序,当服务器在那个时候响应iPhone被锁定时,它会发出http请求(异步调用)。网络连接失败,我收到错误代码-1005“网络连接失败”。如何在手机锁定时保持网络连接,并在手机再次解锁或在后台时允许应用程序接收响应。当用户在收到响应时杀死应用程序时,应用程序也会崩溃。您应该看看。它允许你的应用程序在后台运行10分钟左右 以下是文档中的示例代码: - (void)applicationDidEnterBackground:(UIApplication *)application

我开发了一个应用程序,当服务器在那个时候响应iPhone被锁定时,它会发出http请求(异步调用)。网络连接失败,我收到错误代码-1005“网络连接失败”。如何在手机锁定时保持网络连接,并在手机再次解锁或在后台时允许应用程序接收响应。当用户在收到响应时杀死应用程序时,应用程序也会崩溃。

您应该看看。它允许你的应用程序在后台运行10分钟左右

以下是文档中的示例代码:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
        // Clean up any unfinished task business by marking where you.
        // stopped or ending the task outright.
        [application endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    }];

    // Start the long-running task and return immediately.
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        // Do the work associated with the task, preferably in chunks.

        [application endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    });
}

这可能不是最好的背景模式。执行时间限制为几分钟。后台获取或VoIP模式可能更合适,具体取决于OPs应用程序