Background processing in iOS; Aasim Naseem, June 7, 2012March 12, 2024 Hello everyone; Hope things are going good around you; I’m working on an iOS application and facing an issue regarding network calls; Need your kind suggestions incase I’m not doing the thing in right way; Scenario: I want to download one or more zip files from some urls; The files may have different sizes, ranges from 6MB to 150MB; I’m using ASIHTTPRequest at my network layer; Issue: I found that during download, if user’s device goes in sleep mode or user goes away from my applition (either via pressing home button, or by selecting some other app from minimize bar, or via multi guester with four fingers to swap to next application) the downloading process terminates by throwing either time out or connection break; Hence as a result the downloading fails; I was using following piece of code; [code lang=”objc”] self.request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]]; [self.request setRequestMethod:@"GET"]; [self.request setDownloadDestinationPath:paramFilePath]; [self.request startSynchronous]; [/code] Adopted Solution: Later on, after reading some blog posts, I added the following attribute in my request object; [code lang=”objc”] [self.request setShouldContinueWhenAppEntersBackground:YES]; [/code] But the problem was still there; After spending some more time over stackoverflow, I started using following attribute in my request; [code lang=”objc”] [request setTemporaryFileDownloadPath:tempFilePath]; [self.request setAllowResumeForFileDownloads:YES]; [/code] Somehow my app is now behaving well; If I pick 4, 5 items and start downloading, it doesn’t interrupt the download process even if I navigate away from my app; Questions: So the questions are am I doing it right? Or there are some other better ways to handle such scenario? Moreover when our app enters in background then what happen with our ASI calls (sync/async calls)? Does iOS stop/pause them? or let them continue running in background so that when response arrives our app handle it (due to shouldContinueWhenAppEntersBackground attribute) What is the significance of beginBackgroundTaskWithExpirationHandler and UIBackgroundTask? Another thing is (specially for my scenario) if we start a download process then what happen to this process at time when app enters in background? Does iOS allow to continue downloading the data when app enters in background? Or it just pause it? Right now, I’m assuming that my download get paused and then resume when app will enter in foreground again; Is that right? Plus is it confirm that we can’t continue download progress from foreground -> background ->foreground? We have to bear a pause and resume cycle; Right? Kindly reply in comments about your experiences with such scenarios; Thanks in advance; Please follow and like us: iOS Tips & Tutorials ASIHTTPRequestbeginBackgroundTaskWithExpirationHandlerdownloading in backgroundiossetShouldContinueWhenAppEntersBackgroundUIBackgroundTask
EXOdesk, Your Virtual Desk; November 21, 2011March 28, 2024 Something that will change everything on your desk; I’m just loving the concept; EXOpc has posted a video of its EXOdesk — an interactive desk environment that lets you do all sorts of tasks on a virtual space on your desk — in action and it looks amazing. The actual… Read More
Java 1.7 G1 Garbage Collector; November 3, 2011March 27, 2024 Hi All; Hope everything is going good at your desks; Last night, I was reading new features in Java 1.7 and found some updates in garbage collection mechanism; There are many updates in 1.7 ranges from core vm, i18n, Nimbus for Swings and other enhancements; We have already discussed the updates… Read More
Amazon Kindle Application Development Tutorial – Part 1 October 22, 2010March 18, 2024 Hello All. hope everything is good. From last few weeks i’m working on an application development of Amazon Kindle, an ebook reading device by Amazon. In my last post i introduce to you kindle device. Now its sdk is also available for custom applications. I’m probably the first in my… Read More