16

When using the BLE with CoreBluetooth (no iBeacon), is there a way to wake an app that is not running when the device receives a Bluetooth signal?

I'm simulating a beacon with the RedBearlab's BLE Shield (http://redbearlab.com/bleshield/).

Thanks, DAN

* UPDATE 03/05/14 *

It looks like Apple has introduced a major update with iOS 7.1: now iOS will open your app for you if it detects a UUID that matches your app. The app only needs to be installed, it doesn't have to be running (logic in AppDelegate needed to answer the wake-up call).

gamofe
  • 3,008
  • 4
  • 38
  • 76
DAN
  • 899
  • 1
  • 6
  • 23
  • For further information, see: http://helpdesk.estimote.com/hc/communities/public/questions/200458547--Hear-a-beacon-when-app-is-closed-no-background- – DAN Nov 20 '13 at 09:31
  • You should be more concrete in your update. The post you linked is way too vague to be useful. – allprog May 03 '14 at 19:20
  • DAN's link does not work. Use this one instead: https://forums.estimote.com/t/hear-a-beacon-when-app-is-closed-no-background/1036 – inigo333 Dec 14 '16 at 14:22

4 Answers4

10

If the app was running in the background and then closed (I mean here terminated - and you do not see it anymore in the list of background apps when you double click the home button) due to memory pressure from other apps, then the iOS will take care of waking it up again when a delegate is called (assuming you have background modes listed in .plist).

If the app was running in the background and then closed by the user (again I mean here terminated. So the user double clicked to get the list of apps running in the background and then clicked on your app in the background list until it wiggled and then pressed the 'x' next to the app to kill it) then this is a clear indication that the user does not want the app running in the background and the app will not be re-launched. The user has to relaunch the app for its delegates to start functioning again in the background (new in iOS7).

Update: I am not sure if this is in the documentation but it is in CoreBluetooth WWDC 2013 Video. I recommend you watch it. They spent a good portion of the video on how CoreBluetooth behaves in the background.

Khaled Barazi
  • 8,503
  • 6
  • 39
  • 59
  • I'm thinking about the following situation: you have installed an app related to a shop but haven't used it for quite a long time.. one day you walk by such a shop which uses a beacon to inform people about a special promotion. In that case you'd probably like to be informed about that promotion but are not aware about the app status. Therefore do you state that the previous scenario cannot be achieved with iOS7? Moreover could you point me to Apple's documentation talking about your statement "The user has to relaunch the app for its delegates to start functioning again in the background"? – DAN Nov 15 '13 at 09:32
  • The scenario can be achieved as long as the user never killed the app (by pressing the app icon until it wiggles and then pressed the 'x' next to the app). I edited my answer to clarify what I meant by "closed". I also added details on the Apple's documentation. – Khaled Barazi Nov 15 '13 at 09:51
  • 1
    in iOS7, you kill an app by flicking it up from the list of background up. And just to clarify: I am referring to the user double clicking the home button (to get the list of apps running in the background) and then flicking or pressing the app icon until it wiggles etc.... I am not referring to the user pressing the app icon on the main screen until it wiggles and then pressing the 'x' next to it because that would obviously delete the app. – Khaled Barazi Nov 15 '13 at 10:00
  • 1
    A beacon specifically will launch the app for several seconds in the background even if the user has force quit the app (double tap home and swipe up). I've tested this on iOS 9 and 10. – anders Dec 16 '16 at 16:39
4

From what I understand, if your app has not previously connected with the BLE Peripheral, then no.

If your app has previously connected with the BLE Peripheral, then use:

-connectPeripheral:options

Connection requests don't time out. The best place to call this method is when your app loses connectivity with the BLE peripheral. You will get notified when you lose connection to the peripheral in the CBCentralManagerDelegate Protocol:

-centralManager: didDisconnectPeripheral: error

So the next time your App comes in range of the BLE Peripheral, it will trigger this method. Also note that you will need to set up State Preservation and Restoration when you initialize a CBCentralManager.

David Chu
  • 184
  • 1
  • 3
1

https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html

the system wakes up your app when any of the CBCentralManagerDelegate or CBPeripheralDelegate delegate methods are invoked, allowing your app to handle important central role events, such as when a connection is established or torn down, when a peripheral sends updated characteristic values, and when a central manager’s state changes.

To perform certain peripheral role tasks while in the background, you must include the UIBackgroundModes key with the bluetooth-peripheral value in your app’s Info.plist file. When this key-value pair is included in the app’s Info.plist file, the system wakes up your app to process read, write, and subscription events.

Andrew
  • 3,136
  • 19
  • 32
  • 1
    I meant how to wake app the app when it is closed and not running in background; is there any method which is automatically invoked when a device enters a region covered by a bluetooth signal (i.e. beacon)? – DAN Nov 12 '13 at 15:04
  • 1
    In that case use - (void)startMonitoringForRegion:(CLRegion *)region desiredAccuracy:(CLLocationAccuracy)accuracy and pass in a CLBeaconRegion as the region, that should start the app. Here's some sample code - http://joris.kluivers.nl/blog/2013/09/27/playing-with-ibeacon/ – Andrew Nov 12 '13 at 15:13
  • That's only possible with the iBeacon technology; I don't know how Estimote could implement such protocol as it's not been released by Apple yet. I'm working with BLE on Arduino. – DAN Nov 12 '13 at 16:01
-2

You could try to declare voip in info.plist. For the time being, my application was automatically relaunched after a time, even user terminated it.

mmad
  • 7
  • 1