NSURLSession delegate called only on Foreground

Hi,


It seems that sometimes when there are more than few tasks on NSURLSession the delegates called only once where we the application is on the foreground, altough all tasks were completed.


Can you elaborate if this is expected behaviour ?


Thanks !

Replies

Are you working with a standard session? Or a background session?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I'm working with background download session.

10x

I'm working with background download session.

OK.

Earlier you wrote:

NSURLSession
the delegates called only once where we the application is on the foreground

Which specific delegate methods are you talking about here?

[although] all tasks were completed.

And if you’re not getting delegate methods how do you know that the tasks completed?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Eskimo,


Picking up from your questions about zevikw's last message, sorry to leave you hanging...


When it happens the issue results in no delegates being called when the app is in the background. None of handleEventsForBackgroundURLSession nor the URLSession:task:didCompleteWithError: or URLSessionDidFinishEventsForBackgroundURLSession: are called until only the app is launched in the foreground.


We know that the download tasks are completed because we monitor the network using Wireshark and see that the requested data was downloaded and also when we do then launch the application in the foreground the corresponding delegates are called even though nothing more is downloaded.


This has definitely occurred on iOS 12.2 and we saw it on earlier versions of 12.x and 11.x too. It is intermittent but probably happens at least one in 20 times we create Background download sessions.


Overall we know our implementation works and the fact that the data is downloaded in the background means that the tasks were created correctly and resumed. It is only the delegate callbacks when the app is in the background that are missing. It causes us an issue as the application cannot send the user local notifications to inform them that the download completed. It doesn't seem to matter if the app was terminated in the background or not as far as I can tell.


I haven't figured out a good way to reproduce the prolem. Last time I saw it happen I tried triggering the additional iOS netowrk diagnostics dump when it occurred but didn't see anything useful. Is there a way to confirm that status of tasks in the iOS diagnostic information.


As background information for you, we are creating up to 10 NSURLSessions where each session has 300-500 download tasks. Sometimes more.


Thanks

Neil