NSURLSession URLSessionDidFinishEventsForBackgroundURLSession handler never called ios 8. OK in ios 7

I have an NSURLSession that uploads multiple files. I am updating ios 7 application for ios 8. It works fine in ios 7 but when it matches ios 8 delegate meathod

URLSessionDidFinishEventsForBackgroundURLSession: 

never called.

I dug a little deeper and on

 -(void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location 

and

 -(void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error 

meathods delegate I am checking the session for the remaining download tasks:

 [self.session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks){ ...} 

In the last delegate meathod, there is always one element that is restored in the downloadTasks array. It is strange that this download task does not always refer to the same file, and the status on these tasks indicates that the download is complete.

Again, works fine in ios7. The problem only occurs in ios 8.

+7
ios8 nsurlsession nsurlsessiondownloadtask
source share
2 answers

I assume you are testing iOS Simulator. If so, then another mistake is made for this incorrect behavior. iOS8 Simulator never works with applications, so the completion handler does not start.

Try starting the device and it will work.

You can find the full discussion in the Apple forums or on this blog post.

+2
source share

Make sure you call

  if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){ [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]; } 

in

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

This should fix this on the device, but the simulator has an error that prevents it from working.

-one
source share

All Articles