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.
Related
I am working on a medical related app where a medical device interfaces via bluetooth with an iphone. However I cannot figure out how to allow the app to run indefinately in the background. Right now it only communicates when the app is open. I have been reading a lot of questions related to this and I haven't managed to find an answer which fits. I'm sorry if this is a duplicate. Can someone point me in the direction of how to implement this.
ETA - I just got confirmation that this is supposed to be able to go on the App Store.
Did you come across this question: Background time issue for Bluetooth LE app for Iphone 4s
It seems that adding the background mode bluetooth-central (see documentation) can enable your app to run in the background while handling bluetooth events. As noted in the question above though, you could always set background mode to audio and play a blank looping audio track to keep your app alive and responding if you don't need to be on the App Store.
Is it possible that my iphone application will run in background state and after some time interval it will start another program or application from my iphone.
Suppose, I want to start the camera preview after 10 minute later that will be handled from my iphone. So, my application will run in background state and it will start the camera view after 10 minutes.
Is it possible ???
The only way to start other applications is to use the url schemes exposed by the other app. If it does not expose such scheme, you won't be able to start it.
What about scheduling such thing when you're in the background, you can register for timed local notifications that will show a popup to the user when the time has been elapsed. If the user accepts the popup, your application will get focus and CPU so you can launch also other apps.
There is another option, to get some seconds of CPU in every 10 minutes. It is called VoIP services and you can register for it in the project settings, then it'll call a callback in your app delegate when the OS decides to grant you some CPU.
Study "local notifications" and "url schemes", these are the technologies you need.
Specifically on whether your app can do anything while in the background state, recommend watching the 2010 WWDC video "Session 105 - Adopting Multitasking on iPhone OS, Part 1" : https://developer.apple.com/itunes/?destination=adc.apple.com.4092349126.04109539109.4144345587?i=1907522673
TL;DR: you can only finish up tasks upon entering the background. MrTJ is right about using a timed local notification, and you can also investigate Apple Push Notifications too, if a bit more work and outside the scope of your original ask.
Is it possible to keep a socket connection alive in background, to be able to push new data and alert users at all times?
The answer to this question is a definitive yes. If you are in the background state, then you can keep a connection open and process messages from a server.
Unfortunately the complexity here is that you don't have a lot of control over the state your application is in:
foreground - The user has tapped your icon and the app is running with the UI visible.
suspended - The user was previously running your app in the foreground, but suspended it by hitting the home button or receiving a call. Basically your app is 'freeze dried' and will remain inactive until it is resumed by the user (starting where it left off) or it is terminated by the OS (see below).
background - The app was previously running in the foreground but has moved to the background state as a result of something the user has done. Normally your app will move to the suspended state in this case, but there are things you can do as the developer to prevent the instant 'freeze dry' and go into the background instead (see below). Your app will also be in the background state if it is woken up for a significant change event.
terminated - Your app has been unloaded from memory and the next time it starts will be from scratch. This is what happens when you double click the home button and then tap the x next to your app icon. It moves the app from the suspended state into the terminated state. This will also happen if the OS decides it needs room for more recently running apps and your app has been suspended for a long time.
So obviously the trick here is how do I stay in the background state as a long as possible. There are a couple of ways to do this:
Beg for more time - You can get up to 10 minutes of additional background processing when your app is closed if you ask for it.
Use UIBackgroundMode - You can declare youself a voip, audio or location app by adding the corresponding UIBackgroundMode value to the pList. There are special requirements for these types of apps which you can check out here.
So these approaches are not without their own problems (getting approved on the store being one of them) and as such I tend to agree with the other answers that using push notifications is probably your best approach for notifying your users. With the notification improvements in iOS5 this is going to be the best user experience going forward.
You can keep a socket connection alive (or do whatever else you want) in the background for about 15 minutes after your app closes. There are also more specialized background processing modes (specifically, audio, voip, and location) which Apple supports if your app fits into one of their supported categories. See here.
If you want to keep sending the user notifications indefinitely, you want to use the Apple Push Notification Service. This allows your app to continue to receive notifications when it's not running, and it conserves resources since there's only one connection to the APN service at a time.
You can definitely alert users with local and push notifications.
And as far as I know, you can keep a connection open only for limited time.
Look here for more details.
Let's say the user leaves the phone on the table. (probably on home screen)
A few hours later, he picks it up. And when it does, the iPhone detects the accelerometer, and it rings.
Unfortunately, this is not possible. Once the OS goes to the home screen, applications running in the background have a limited set of options.
Read this article for more information: http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
Not through officially accepted means (i.e. you could do it on a jailbroken phone conceivably). Primarily, you can't run in the background for that purpose. If the app was running in the foreground, you can easily detect motion and perform an activity - but if the phone is left for too long a period without activity, it will sleep.
Unfortunately, the accelerometer is not one of the specified keys in the UIBackgroundModes option in your apps info.plist.
auido, location and voip are the only ones available for now.
short answer: YES
The trick is to make sure the app doesn't get backgrounded when the phone goes to sleep. The other elements like detecting changes in the accelerometer and playing a sound are all standard features.
As for the no sleep solution, it has been asked before, basically is you play a music sample the app will continue running, so perhaps a loop of silence continuously played.
Only if you left an app designed for that purpose running in the foreground.
It won't be possible if your app is running in the background.
Can you have a program running in background respond to SMS? I basically want my program to sit in the background so the will be iOS4+ and when someone text messages you, the app can then do something with that text.
Can this be done?
I have seen that the question has been asked before, but it was before the iphone could have background apps.
No backgrounding is very limited on IOS. There is only a handful of stuff you can do. You can always send push notifications to get an alert while the app is not running in the foreground.
From Apple:
OS 4 delivers seven new multitasking services that allow your apps to
perform tasks in the background while
preserving battery life and
performance. These multitasking
services include:
Background audio - Allows your app to
play audio continuously. So customers
can listen to your app while they surf
the web, play games, and more. Voice
over IP - Your VoIP apps can now be
even better. Users can now receive
VoIP calls and have conversations
while using another app. Your users
can even receive calls when their
phones are locked in their pocket.
Background location - Navigation apps
can now continue to guide users who
are listening to their iPods, or using
other apps. iOS 4 also provides a new
and battery-efficient way to monitor
location when users move between cell
towers. This is a great way for your
social networking apps to keep track
of users and their friends' locations.
Push notifications - Receive alerts
from your remote servers even when
your app isn't running.
Local notifications - Your app can now
alert users of scheduled events and
alarms in the background, no servers
required.
Task finishing - If your app is in
mid-task when your customer leaves it,
the app can now keep running to finish
the task.
Fast app switching - All developers
should take advantage of fast app
switching, which allows users to leave
your app and come right back to where
they were when they left - no more
having to reload the app.
Nope. The only way for your application to be "called" when it's not already open is by sending a push notification.