NSURLSession Background task stops while clicking the home button? - ios

I have develop a HTTP module for making upload download request using URLSession Background sessions.
The HTTP module work in Serialize mode as specified in URLSession doc by passing nil to queue.
On download complete urlSession(_:downloadTask:didFinishDownloadingTo:) i do parsing.Based on parsing make request for other file from the same module.
Everything works OK in foreground.
But as i move the application to background by pressing home button downloading and parsing stops.
Because of which i can't able to make another file request in background.
And if application move to foreground downloading will resume.
Can any one help me out for this ?

Related

Alamofire request gets stuck when entering background

When I download a file and I'm inside the app everything works as it should, but when the user gets a call the download just stops
I read a bit and saw that it might be possible to use BGProcessingTaskRequest
But I don't know how to use it with Alamofire

URLSessions give URLResponse nil when app goes to background

I use URLSessions to do my network calls and it always fails when I put my app to background state.
When I bring the app to foreground state, the URLSession give URLResponse as nil.
How can I make it work in background state?
You can get URLSession to work in background state if you configure session for background download or upload. But if you use session for regular backend API call, best that you can do is to repeat call after application enter foreground again.

Is it possible to make network request when app in background?

Dev Environment :
Xcode 8, XCode 9
AFNetworking for network request
My app need to upload some media to server, when its done i need to call the api to POST some JSON Data to server in both case Application in Foreground and Background
My problem is:
When application is active, i making request upload media to server (request 1) and press Home button (application enter background). All the media was uploading success in the background, in success block of upload media request (request 1) i making another request to POST some JSON data to server (request 2) but this request (request 2) can't excute in the background. When i enter the application (application enter foreground). (request 2) trigger automatically.
I need to make (request 2) execute in the background. Is it possible to do this?
Please help ! Many thanks !
At background upload file that you need apply more time.
The iOS has 3mius give you using.
You can review "beginBackgroundTaskWithExpirationHandler".

resuming upload of file after app crash using nsurlsession

I want to upload a file to a server using NSURLSession.
Cases Are:
1. It should resume uploading a file to the server from where it stopped because of app crash.
2. It should handle background upload as well.
Try AFNetworking Library to upload image asynchronously.You can find a brief example in this thread.
You should use background NSURLSession. If your app crashed or user left the app while upload was in progress, with a background NSURLSession the upload would continue seamlessly in the background. When the upload is done, your app will be notified of this via the delegate (and if your app wasn't alive at the time the download finished, it will be started in a background mode, at which point you can do whatever cleanup you need).
So create NSURLSessionConfiguration with backgroundSessionConfigurationWithIdentifier, and then instantiate a NSURLSession with that configuration.
There are a few caveats:
You cannot use completion handler pattern. You have to use delegate-based implementation.
You have to implement handleEventsForBackgroundURLSession in the app delegate, capturing the completionHandler it passes you and also instantiate the background session again. Likewise, in your NSURLSession delegate methods, you have to implement URLSessionDidFinishEventsForBackgroundURLSession, which will call the saved completion handler.
For more information, see Background Task Considerations in URL Session Programming Guide, see a section of the same name (but different text) in the NSURLSession class reference, or see the WWDC 2013 What's New in Foundation Networking, where Apple first introduced us to background sessions.

AfNetworking download is not successful if phone sleep or a call comes

I am trying to download 4 video files, each one is approximately 50MB, using AfNetworking. I added this block to handle background download operation:
[weakSelf.downloadOperation setShouldExecuteAsBackgroundTaskWithExpirationHandler:^{
// Handle iOS shutting you down (possibly make a note of where you
// stopped so you can resume later)
}];
When it is downloading, if a call comes, or the phone goes standby mode, file seems to be downloaded, but actually it is not fully downloaded. So the app cannot open the downloaded video file. What should I do for that?

Resources