Вопрос

I recently completed my first project using the new NSURLSession available on iOS 7.

I built an app to explore the whole API of NSURLSession, implementing all kinds of tasks: - Data Tasks - Download Tasks - Uploaded Tasks

I also implemented background uploads using background sessions. After many hours of debugging and trial-and-error implementation I finally arrived at a point where the whole apps works without any issues - for me that is. I released it to a small number of testers (< 5) and some of them experience a bug that I can't seem to reproduce or even track it down.

A certain part of my code - after some unrelated operations - is responsible for resuming the current uploading tasks available on a background session:

    [[appDelegate getNSURLSessionForBackgroundTransfers] getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {
    for(NSURLSessionUploadTask *task in uploadTasks) {
        [task resume];
    }

From time to time, the app crashes with the following exception in my logs (I'm using hockey app):

SIGSEGV

On:

0   libdispatch.dylib                   0x3ba87772 _dispatch_async_f + 10
1   CFNetwork                           0x30a5b86f -[__NSCFBackgroundSessionTask _onqueue_connection_resume] + 92
2   Memoir Beta                         0x00231e85 __55-[PhotoBinariesUploader runCodeEvenIfBackgroundMode:]_block_invoke_3 (PhotoBinariesUploader.m:553)
3   CFNetwork                           0x30a848c5 __50-[__NSCFURLSession getTasksWithCompletionHandler:]_block_invoke246 + 14

Any ideas ? Any hints for what it might be ?

Thanks in advance! Ze

Это было полезно?

Решение

I've seen the same issue starting with iOS 7.1. The crash happens if you call resume on a task with state NSURLSessionTaskStateCompleted (maybe for NSURLSessionTaskStateCanceling too). I think this is a bug introduced in iOS 7.1 because under iOS 7 the resume was ignored.

What I did is the following:

  if (task.state == NSURLSessionTaskStateSuspended) {
    [task resume];
  }

This should prevent the crash from happening. And only tasks that are suspended can be resumed anyway.

It's still frustrating since it worked without issues under iOS 7 for months and now a released app generates lots of crashes because of this.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top