I want to initiate a separate thread apart from main thread and do some operations continuously even when my app is closed. I tried detachNewThreadSelector, but it doesn't work continuously and that too it needs my app to be launched.
And whenever I don't need it, I want to stop the thread as well. It is possible in Android, don't know how to do in iOS. How can I achieve it, could someone guide me on this? I am developing on iOS 4.3 SDK.
You can't create a thread on a stock OS iOS device that will run in the background always. Some types of apps, such as for VOIP, audio play/record and GPS monitoring, can register for callbacks when the app is in the background.
Related
I wrote my first iPhone App, and managed to get it into the App store. I later discovered a bug that happens on a real device but not on my emulator. I have committed a fix (changed plist to prevent app running in background), but I don't really understand why it happened.
My App allows users to record a sound-byte, however while they are recording they can use the iPhone home button to move the app to the background, and then it can keep recording forever if they don't restart the phone or the app does not crash.
My impression from everything I have read, is that this should not happen as you have to ask for background audio specifically if you want to do this, but now it appears to me that you have to ask specifically to disable it.
Could anyone explain this to me?
The iOS App lifecycle is described in Apple's iOS App Programming Guide.
The App is given the opportunity to save data and otherwise stop things that don't need to be running, before being suspended. You can request extra time doing this by using beginBackgroundTaskWithExpirationHandler:.
If you want your app to stop doing its "normal thing" when it is put into the background then you need to detect the App state transition and stop it yourself.
I hope to run an app in background on ios4
I know
Apple allows only certain types of apps to run in the background, like navigation and audio and VOIP apps. But even those are limited to only the necessary tasks.
Is it possible I register the app as one kind of VoIP, Audio or GPS apps to keep it run in background?
Welcome any comment
You can't "run" an app in the background; you can only run a task in the background. The tasks are
Continue Playing Audio
Maintain VoIP Connection
Update Location (GPS)
Some Finite Task (such as uploading a file)
I haven't developed for iOS so there might be something I'm missing. Read more at Executing Code in the Background. As of iOS 4, developers don't have the ability to implement true multitasking. Correct me if I'm wrong in any of this.
Not in general, no. You could register a VoIP or GPS session and abuse its callbacks for certain tasks, but I doubt the App Store review process would take kindly to it.
What do you need to do in the background that isn't covered by task completion or the audio/VoIP/GPS background modes? it might be possible to use another paradigm and still get the cake.
I know that the system can close Bonjour sockets while the application is suspended.
But ,will the system allow me while my application is in the background to only discover other devices not creating sockets to them and perhaps store those devices in a list or something like that ?
Use UIApplication's method
- (UIBackgroundTaskIdentifier)beginBackgroundTaskWithExpirationHandler:(void (^)(void))handler
you can run your code in background up to 600 seconds on iOS 4.x and later versions.
Your app can only run in background for audio, voip or location. So there is no way other then the previous mentioned methods to run an app in the background.
IOS4 allow application to run in background. Is it possible to have an application running in the background and not killable without a password?
The simple answer is no.
IOS can always kill your app if it doesn't behave or if memory is needed. Likewise the user can always kill the app if he feels like it.
I don't really understand why you would want this feature anyway?
No. And background tasks are quite limit in their use cases. With exception of location services and audio things, its essential fast app switching / app pausing.
With the support of multitasking in iOS 4.0+, is there any way that I can have my application run in the background and detect the launching and exiting of other applications?
I know you can do this in Android, but I was wondering if this was now possible on the iPhone.
iPhone's backgrounding feature puts the process to suspension which the user code can no longer control the app until it becomes active again. Therefore, even if another app is launched or exit, the backgrounded app cannot catch the notification.
(Anyway, to detect whether an app with ID com.yourcompany.foo becomes active or suspended, you could listen to the com.yourcompany.foo-activated and com.yourcompany.foo-suspended Darwin notifications.)
Under the stock iOS, apps don't run in the background, only specific allowed tasks do (audio, VOIP, location logging, etc.)