We are trying to monitor a Bluetooth LE device as a background task on iOS.
Everything is working fine, except the background task runs only when the display is turned on.
This is not what we want, because we want background monitoring while the phone is not in use.
We are searching for information about why and how apple does this, but there is nothing to be found.
Does anybody know if it's possible to keep running background tasks when the display is turned off?
Yes, this is possible - see the "Background Execution Modes" section of the Core Bluetooth Programming Guide. Your app must declare its background mode in its info.plist file, and your app will only be woken on a BTLE event. Also, note that when you call scanForPeripheralsWithServices:, you must specify a list of services in which you are interested - if you use the default of nil your app will never be woken.
Related
I built a reminders app, it wont work in background mode, and warns reminders via push notification.
But starting from the moment the User turn off your device (iphone or ipad) and turn on, my app is not this more in background mode, in which case reminders are no longer advised.
In this case, I like to find a way to make my app starts with the device but in background mode (the same happens with windows programs, android apps, and osx programs).
You are focusing on the wrong question. The question you should focus on is, "How do I ensure that my app's reminders will be delivered to my users even after a device restart?"
The answer is to set a Local Notification with a future delivery date, at the point the reminder is created, which of course is while your app is running. There is no need for your app to be running, in either the background or the foreground, for this notification to then be delivered at the specified time.
check project setting in .plist set UIApplicationExitsOnSuspend is YES
The app which I submitted does not have any background location mode. I am not having "Required background modes" field in my plist.
I even checked the device capabilities, Background modes is off.
From Apple as follows,
we found that your app uses a background mode but does not include the following battery use disclaimer in your Application Description:
"Continued use of GPS running in the background can dramatically decrease battery life."
Can any one please help me how to find out whether my app is using background location mode or not ?
This link will tell you about Background fetch.
If you really need the app to constantly monitor the location of the user's device then you should put the disclaimer in your app's description.
Remove CoreLocation Library from your libraries/frameworks folder and resubmit.
Does anyone know if core BLE continues to run in the background after a user force quits the app in iOS 7.1? Or does just iBeacon continue to run? I know that neither will continue to broadcast on force quit, but will both continue to scan?
EDIT: I've attempted to test the current implementation I've had and it doesn't appear to be running in the background after force quit. What I've heard so far from other sources is that it does but it doesn't appear to be running for me with the standard CoreBluetooth implementation.
For CoreBluetooth (CBCentralManager and CBPeripheralManager), the following rules apply:
If the user closes the app manually using the app switcher, the BLE part of your app also gets killed.
If the user does not close the app manually, you can use the bluetooth-central and bluetooth-peripheral background modes to get relevant callbacks while your app is backgrounded. However, iOS may still kill your app under memory pressure or for whatever reason, in which cases the BLE part is also gone.
To keep the BLE part alive, you can use restore identifiers when instantiating CBCentralManager and CBPeripheralManager. Managers with a restore identifier are kept alive even after iOS killed your app, and if an interesting BLE event occurs), your app will be launched into background and you will be passed the state of the managers when the app got killed for restoration.
The main queue is suspended during background execution - make sure to configure the managers in a way that events are not dispatched on the main queue.
If the user closes the app manually using the app switcher, restoration is forfeited and the BLE part of your app won't stay alive.
To test restoration, you need to resolve to using tools like BackgroundKill. Note that the Xcode debugger may keep your app alive, so make sure to disconnect the debugger first (which will kill the app), then launch your app, then open BackgroundKill and examine the Console output in the Xcode Organizer window.
Yes, it continues to run. This is a change in iOS 7.1.
See my detailed answer and test procedure in the comments here: https://stackoverflow.com/a/22365156/1461050
I am working on UIAutomation. I need to change the location when the app is in background. I have tried following line of code:
var target = UIATarget.localTarget();
UIATarget.localTarget().deactivateAppForDuration(30);
target.setLocation({longitude:77.50, latitude:12.50});
but target.setLocation is not getting called until the app comes to foreground.
Could any one please tell me how I can change the location when the app is in background.
Unfortunately UIAutomation can only automate the application it's attached to. When the application is not "active", it has nothing to talk to. Using lockForDuration, deactivateAppForDuration , etc blocks while it relinquishes control to the system, making your app inactive. While the application is in that state UIAutomation can't send it any more messages.
I would recommend filing a radar asking for the ability to set the location while the application is inactive.
When I ran into a similar problem in the past I had to use AppleScript to change the location of the simulator to get the effect I needed.
You have since updated your comments indicating you are testing a navigation application. Well! That's a little different. If you do not ACTUALLY require UIAutomation and were only trying to use it as a way to set the location:
Xcode does allow you to simulate a route using GPX files, and this CAN be used with Instruments.
Find an appropriate GPX file, preferably one that is a track.
Go to the scheme for your project. In the Run action, go to the "Options" tab. Check "Allow Location Simulation" and use the drop down list to add your GPX.
Run your application from Xcode.
...
Profit!
I think you can use update part in background as service. Though i am newcomer in this world. You can try this. Thanks
if you want your app to execute methods in background, you have to enable "background mode" in your capabilities tab of your app. you have to choose a mode, for example "location updates". but be careful: apple has restrictions of what kind of apps are allowed to run in background. the "location updates" mode are only allowed for apps like navigation apps. see the app store guidelines for details.
if you dont set the "background mode" to yes, your app has 5 seconds to finish executing tasks after turning to background and then all tasks will be stopped and never called until your comes to foreground again.
Refer the http://code.tutsplus.com/tutorials/ios-7-sdk-working-with-background-fetch--mobile-20520 for the Background fetch. I hope this helps you.
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.