I need to create an app which can handle movement events while running on the background.
i.e each time an accelerometer event is happening it should be tracked in the application memory-when the application is running in the background.
My questions are :
1. Is it possible on IOS?
2. How can it be done?
(I came up with some relevant questions but i'm not sure that the answers are up to date due to IOS changes.)
Thanks,
Asaf
You should have a look to this thread (and the links inside) and the apple documentation.
To summarize no third party apps can run in the background (even though some of apple apps do this) excepting for:
Tracking the User’s Location
Playing Background Audio
Implementing a VoIP App
Downloading Newsstand Content in the Background
Communicating With an External Accessory
Related
I searched informations about possibilities when running an iOS app on background, but I didn't found same on different sites.
My application has to read the battery level (with step of 1%) and the time, but I don't know if I can read that when running on background.
Please if someone is sure about it or know a site to read these infos, it will be very nice.
EDIT : I've one more question, can I just open my app (to perform more actions) when the notification center return a battery state under 5% for example ?
No, you can't.
It's not possible to let your app running on background, it's iOS system's limitations.
In iOS 7.0 and later, you have opportunity to do some pre-fetch stuff even your app is not running, through the method like application:performFetchWithCompletionHandler:, but you should tell the device by posting remote notification from your server.
I am really stuck on this problem and I need your help! I'm doing an iPhone app.When iPhone swap between app and Facebook redirection in safari , iPhone shutdown the app for memory saving.
What I am doing is I am providing fb sharing in background from my app.
When I am doing fb sharing its shares successfully in background and comes back to my app successfully.At that time my app is not crashing. But when I go to safari and type Facebook and open fb site to check my shared post , in background my app is crashing.
This issue is coming in iPhone with iOS 7, I am not facing this issue in iOS 8.Check this post : Prevent IOS to shutdown an app when it app switch to facebook for login and permission request but this solution doesn't work for me as I am using pod to install fb and doing background share.
Though it's too late to answer this but I believe it may be helpful for others.
In App Programming Guide for iOS under "Being a Responsible Background App" section it was said that
your background running app would be terminated if it doesn't follow one of the given requirements.
You can familiarize with the full documentation. I'll quote 2 of them which exactly fit your problem:
Being a Responsible Background App
The foreground app always has precedence over background apps when it comes to the use of
system
resources and hardware. Apps running in the background need to be
prepared for this discrepancy and adjust their behavior when running
in the background. Specifically, apps moving to the background should
follow these guidelines:
Do not make any OpenGL ES calls from your code. You must not create an EAGLContext object or issue any OpenGL ES drawing commands
of any kind while running in the background. Using these calls causes
your app to be killed immediately. Apps must also ensure that any
previously submitted commands have completed before moving to the
background. For information about how to handle OpenGL ES when moving
to and from the background, see Implementing a Multitasking-aware
OpenGL ES Application in OpenGL ES Programming Guide.
Do minimal work while running in the background. The execution time given to background apps is more constrained than the amount of
time given to the foreground app. Apps that spend too much time
executing in the background can be throttled back by the system or
terminated.
To sum up, maybe your app is doing one of the above-given tasks when it's moved to the background after Facebook sharing.
I want to develop an Enterprise Application. It will run in the background continuously and from the background i want to open an another application. Its like toggle between two application. I have implemented forever background running with help of Location services which is working fine and also updating the location from the background but it is unable to execute openURL method.
Please suggest something.Thanks
It's not possible!
You can use these links only.
https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html
I will extend a little bit on MobiDevCom answer.
I haven't found a good publicly known solution.
The direct approach (trying to open something from background using all kinds of public or private API) ends up requiring all kinds of entitlements. I tried at least dozen of things about a year ago and reverse engineered quite a lot of iOS components.
The only idea which I found was usage of MDM Guided mode (however, a device needs to be supervised and enrolled into MDM for that).
BTW. Here is the question which I asked - Show some UI from background in audio player or VOIP app on iOS
I'm building an activity analyzer application for iPhone and I use iOS 7. In order to do these i use CMMotionManager and I access accelerometer data.After this I write the datum to database. My application has to work also in background and I used queues, GCD, blocks and other such things in my code to do this properly. Problem is, all of these are working properly when iPhone is plugged in with Xcode but if I run the app without Xcode, app runs about 4 or 5 minutes.After, it is terminated.What is the reason for this?
iOS apps can only run in background, if they fit in one of apples defined background modes such as "App registers for location updates","App provides Voice over IP services","App plays audio","App processes Newsstand Kit downloads","App communicates using CoreBluetooth"",App shares data using CoreBluetooth" and a few more. All background modes you will find in xcode in the capabilities section auf your project(click on project name upper left->mainwindow->second tab).
if your app fits into one of these modes, you must enable this in your app.plist by setting the checkbox in the capabilities section.
if your app doesn't fit in any of these modes you can run in background only a limited amount of time and then iOS stops all activities.
For testing you could start any background mode. but when your app shall be reviewed for deploying via app store apple will reject the app if you use the background mode without legitimation.
The reason for this is that iOS 7 (actually all versions of iOS) will suspend a background task, and potentially terminate it if it's misbehaving, only certain kinds of apps can keep running. Here is the apple doc on it: https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW20
So, given your situation, you'd most likely have to "lie" about what type of app your app actually is, which will get you rejected from the app store.
If you do decide to go the route of a hack, be very careful about battery life, cpu usage, and memory usage, as there is a reason apple did this.
FYI: The "type" is set in your Info.plist file.
I'm newbie iOS. I have been develop Phonegap for Android and iOS. My App is update data from server every 1hour. In Android, i use service to do that. My app in Android working very good. Now, i want to develop version for iOS, and i have problem when update data from server every 1hour. I was research but not find anyway for my app.I don't know what's solution to replace for service in Android. Can you help me, what's solution. This have been kill me. Thank you so much.
Short answer is NO as Apple has restriction on background task running especially cases like yours.
But if you are downloading small amount of content, you do have some other options. From IOS 4.0 or above, you can declare your app to run in background when you fall under the following categories:
Audio
Location updates
Voice over IP
Newsstand downloads
External accessory communication
Bluetooth networking
Bluetooth data sharing
Background fetch (IOS 7)
Remote notifications (IOS 7)
In order to do so, you need to flag your app in the info.plist for Required Background Modes option. Apple will review your app specific in this area once you declared the option.
For your case to download the data, the possible option is to use the new feature in IOS 7 that's the background fetch or remote notification above. The suggestion from DOM was not asking you to download the content through push notification. But instead to use push notification to wake up your application and start downloading new content.
If you don't want to use push notification, the only way to go is register for background fetch. However, no matter which option you want to use, each download will only last for 30 seconds. And after that, your app will put into suspension mode again.
you can have a look on the link here:
Declaring Your App’s Supported Background Tasks
I think your best bet would be to use the push services instead of having your app go get data. Making your app do it is unreliable with phonegap apps because you cant create a service interface and you can not guarantee that your app will be running. With push service though, if your app isn't running, it will be woken up in a manner of speaking.
Take a look at this great how-to article that also discusses what push provides you.