I would like to detect when user unplug his earphones. It seems we can do this by using the audio route related functions as AudioSessionAddPropertyListener.
I have a question though:
Is it possible to use this both when application is open or running in background?
If yes, what happens if the user keeps the application running in background for a long time? Will I still be able to detect when user removes his earphones?
Related
I want to build a application that interacts with my BT device and wakes him.
I want to know is it possible for my application to get notified every time the device asks for connection. Take into consideration that the application is not active.
For example, when i get into the car it connects automatically to my car BT and when i get call, the call application is activated? (but maybe that's something that iOS internally does...)
Any ideas?
It's not possible for applications to catch such events in the background mode. While in the background the app is completely paused (except for some special cases) and can't catch anything at all.
I've seen application on iphone called "moves"
the gps is running on background while the application is totaly closed and not working in the background.
how can i get the location of the user and send it to the application while it is closed and not working on background? how could this possible?
what is the function to do that?
thanks
It is possible to get the location while the phone is running in the background (The Google Maps app does this), however running a background thread is a privilege that you must justify to Apple in their review process.
Here is some documentation by Apple for guidelines for running in the background
You register for the significant-change location service.
According to the Apple docs:
If the app starts this service and is then terminated, the system relaunches the app automatically when a new location becomes available.
This is not possible for an App on a non jailbraked iphone. Check again what you really have seen.
Apps can run in the background and get locations. But an app which is closed, can not do anything, since it is not running.
Maybe you have sawn the GPS Arrow in the status bar, staying active. But this disappears after some seconds, as long as no other application uses GPS.
when we press on the Home button two times then we see the all the apps running in the background.if no apps is running in the background then there are only two controls by default.So my question is can we add same functionality in our app? means i want to add some more controls on the background. if yes then how?
You cannot add background functionality to your app.
The only ways an application can be controlled in the background are via:
Audio events. Your app registers and audio session and the user can press play/pause, next, and previous on the lock screen, task bar, or remote headphones. Unless you're doing audio-specific programming, however, you shouldn't use this.
Push notifications. Your app receives messages from a remote server via Apple's APN, triggered by one of your servers - maybe by a website application.
Sensor listening. It's possible to have your application process in the background inputs from hardware sensors, such as the accelerometer, compass, or GPS. However, this kills battery life and is discouraged unless it is absolutely necessary.
So to answer your question, no.
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 need to write an application, that every 10 minutes it should be awaken from suspended mode, get user location via gps and send this information to the server by network.
Depending on the response it should return to the suspended mode or show local notification to the user.
Is there a way to do this on iOS 4?
I've tried different approaches, but the only working for me was to start monitoring user location in backgroind and declare the application as location background application. In that case it worked in background and has a network connection. But this approach takes a lot of power and not accepted cause application should work 24/7.
May be there is a way to write some daemon that should work in background and wake my application every 10 minutes?
Apparently, Pastebot tried to do something similar with the 'audio' multitasking declaration (by playing a silent audiofile) and got rejected.. UNTIL they actually presented a option to the user to pick which audiofile they wanted to play. It's in the appstore now. :)
In this case: What is your reason for not wanting to use the location updates? If battery-usage is a concern, you can use the 'significant location changes only' option, after which you can temporarily change to a more accurate option.
This isn't possible outside of the method you have already tried.
The iPhone background task API will allow you to run a location service in the background.
There is no way to write daemons for the iPhone without jailbreaking, and that is not something I'm able/prepared to help you with.
App store friendly: use new APIs in iOS4, which allows u to make use of GPS location
Anti App store: create a daemon by adding a specific plist file to System/Library/LaunchDaemons/ and put ur app under Applications/. this approach requires a jailbroken iPhone however...
detailed information plz google the following keywords: daemon, multitask, background, etc...
cheers, Lloyd