In my app I give the user the ability to download files from a server. For that I use NSURLConnection. I would like to give the user the ability to pause and resume the download by tapping a button. I couldn't find any way to do this besides calling the cancel method and then creating a new NSURLConnection. So is there an elegant way to pause NSURLConnection?
Thanks
That's the only method I'm aware of. If your server supports the "Range:" header, you can then create a new connection and have it pick up where the other one left off.
Related
After iOS 3.2, Apple allowed us to keep running our application in background mode. Using the same concept, in my application I have downloading functionality implemented which runs over in background mode.
The problem is that whenever I force quit my app manually, (Double tap on home button > long tap on app icon > tap on cross button of app) as per Apple specifications. I am not able to track that event in code, hence I am unable to track my downloading data.
Because of that, my data is being lost. So how to track this and track/save data before it gets force quitted.
Reference: AppDelegate Protocol
As far as I know, there is no way to handle that event, since it kills the whole process immediately.
You will need to save your data periodically or just leave it like it is. User killing apps, should be aware of that he is killing apps.
track each 'chunk of data' as you receive it and you write it to disk. that way you don't have to rely on a shutdown event
Thats how ASI and AFN do it and thats how you could also manually do it using NSURLConnection directly.
On startup, see if and how much of the data you already have in the file. Again ASI and AFN make this really easy!
I have an application that runs in the background, I need it to pseudo randomly take a picture using the forward facing camera and send that to a database.
A possible solution I thought of was to use URL schemes to open another application, which will take the picture and send it, then use another URL scheme to open the background application back up. Does anyone know if this is possible?
Or perhaps there is a better solution.
It is not possible for an iOS application in the background to initialize, utilize, or grab photos from the camera hardware, let alone store or upload them to a local database.
Not only is this a security risk, but it poses a potential privacy invasion, and is just plain creepy. Besides, background apps only stay alive for 10 minutes or so, so even if this activity were possible, sustaining it would be impossible.
However, it is possible to use the camera directly from an active app without having to delegate the task to another application (perhaps you are thinking a little too much like an Android developer :p). Take a look at UIImagePickerController.
There's a very limited set of actions background applications can do—GPS, audio, phone & VOIP calls, and a couple of others. Accessing the camera is not one of those allowed actions, so you can't take a picture in the background.
As an alternative, you could set up a notification system to alert the user that it's time to take a picture (for whatever reason), and if they choose to open the app it could do your required actions then.
I need help, working on iPhone app using phoneGap 0.9.6.
while using app I want to block all incoming calls because i do not want the application to be interrupted.
Can any one help.?
No, you can't do this with any public APIs.
However, your application delegate will be notified when a call comes in, and you can prepare for this (save data, pause, etc.).
Is it possible? I don't think you can block calls in application.
Maybe you can detect Airplane mode & ask user to switch to Airplane mode if they haven't.
You can't. See also http://www.iphonedevsdk.com/forum/iphone-sdk-development/20349-how-do-i-detect-call.html
I need to download some images from the Internet and right now I'm using NSOperationQueue.
I want to know if it is possible to receive an Internet connection notification to be able to pause/resume the download.
I don't need to freeze the download, but just being able to put it (the NSOperation) back on the queue and wait for connection to start it again would be awesome.
Any ideas?
:)
After checking for reachability, you can set the NSOperationQueue length to 0 if it's not reachable. That way you can effectively pause it.
See this link for further help. You could use the code with apple documentation listed.
WAN detection and airport detection is shown in the code.
http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html
Is there a way of getting the preload progress of a MPMoviePlayerController?
At the moment I'm listening to for MPMoviePlayerLoadStateDidChangeNotification and showing a UIActivityView until the loadState is MPMovieLoadStatePlayable || MPMovieLoadStatePlaythroughOK.
However this can take a few seconds so I'd like to show a UIProgressView instead, so that the end user can I get an idea of how long they have to wait before the video will start.
Is this possible without using private calls (the app will be submitted to the app store)?
This functionality is not available. If you feel that it should be then please file a feature request at http://bugreport.apple.com. Apple keeps track of what people request and if there is sufficient interest they will add this.
Prior to iOS 5.x I used to be able to show a progress bar that indicates how much of the stream is buffered using the playableDuration property. However, this doesn't seem to work after iOS5.x.