In a recent project I'm working on video downloading using AVAssetDownloadURLSession. I'm using AVAssetDownloadDelegate to listen to any download updates. Using the below method I'm able to get the percentage download updated for each download task.
urlSession(_:aggregateAssetDownloadTask:didLoad:totalTimeRangesLoaded:timeRangeExpectedToLoad:for:)
Issue:
The above method doesn't get called when the app is in Background. There is nothing mentioned in the Apple docs regarding the method's foreground and background behaviour.
How can I clarify how the method works? And what is the way around if I want to get the background updated as well?
Related
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
I create a timer,through open the GPS keep App alive every 3 mintues,and then upload data.Then I found the timer was suspended,but the app was alive.Please someone tell me?
You need to become acquainted with Background Execution, here are few useful links I've found so far:
https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
https://blog.newrelic.com/2016/01/13/ios9-background-execution/
https://www.raywenderlich.com/143128/background-modes-tutorial-getting-started
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.
I am using Dropbox's SDK API V1 to upload files from my iOS app. The files aren't loading in real time, but rather I push them into a queue, and they get uploaded in the background.
I can't figure out for the life of me how to take DB RestClient delegate and make it respond to a completion/failure event that happens in the background. Is that even possible?
It seems (and I am new here), that delegates are meant to respond to live events on screen. Is that even an option to assign them to anything other than a UI element/view?
Update: Adding some description of what the code looks like.
There is a lot of code and it's hard for me to tell what's relevant for this question.
I am using PHPhotoLibrary.sharedPhotoLibrary().performChanges() which has a completion handler.
On success, I send an image upload request via dispatch_async(dispatch_get_main_queue()) method.
Dropbox API has this method dropboxRestClient.uploadFile(filename, toPath: pathOnDropbox, withParentRev: nil, fromPath: localFileUrl)
In all the examples that I've seen, dropboxRestClient.delegate was assigned to a UIViewController of some sort, and never to anything else.
So I am not sure how to assign it correctly, so that it recognizes events that happen in this queue.
I'm designing an app that needs to have access to an RSS feed at all times. I need to be able to access this feed in the background, while the app is not running. I already have all the code I need to access the feed and extract the info I need.
Thanks for your answer!
I don't have the exact implementation because I haven't tried it myself but Apple introduced background tasks with new SDK.
So basically you register for a background task like downloading content in your AppDelegate's
- (void)applicationWillResignActive:(UIApplication *)application
and when application becomes active you check to see if there was any new content. Again, this is a very raw explanation but hopefully should get you started.
**EDIT***
Check this out :
http://www.raywenderlich.com/29948/backgrounding-for-ios
Although this does not talk about download content in the background