Etan and Andras,
Awesome. This now works!
To summarize your excellent responses:
If I want to do event-based backgrounding, I just need to make sure I have set the proper option during the connection to the Peripheral. For this I do NOT need to change the info.plist.
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBConnectPeripheralOptionNotifyOnNotificationKey]; [CM connectPeripheral:activePeripheral options:options];
If I now background the app, the iPhone will pop-up a message to the user and allow the user to launch the alerting app. This works, but there is no control over what that message is.
On the other hand, if I want a bit more control over what happens when I get a background notification, I should 1. Add the UIBackgrounding key in the info.plist. Required background modes: App communicates using CoreBluetooth 2. Create a localNotification whenever I get a new datapacket while I am in suspended mode.
Anders
On Oct 26, 2012, at 10:38 AM, Etan Kissling < email@hidden> wrote:
Anders,
When you connect to the peripheral, there is an options dictionary that allows you to specify the behaviour of the popups. Please take a look into the corresponding header file in order to find the correct dictionary keys. One solution would be to disable
the popup from the iOS itself and instead send a local notification with a custom text to the user.
The bluetooth-central mode is designed for your use case and using it should be perfectly fine to get in the app store as it is currently the only way for this type of communication in backgrounded mode.
Note, however, that every noticication from the peripheral will wake your app up for at least 10 seconds. Therefore, you should use notifications sparingly in order to save battery life.
Etan
On 26.10.2012, at 19:11, "Anders Grunnet-Jepsen" < email@hidden> wrote:
Thanks for the quick response.
If I do set the info.plist property for "Required Background modes" to "App Communicates using CoreBluetooth", then I do see that my communication continues.
However, my understanding is that this is "Session-based Backgrounding" and that this should be avoided if possible. Since I am fine with the user getting a pop-up alert saying that my app wants to communicate an event, then the "Event Backgrounding" is
what I need to use.
Here is what I think I understand about the two models:
1. Event based (most common model)
- Apps may NOT interact with the peripheral while it is in the background.
- Keep connected to peripherals while in the background.
- Peripherals can send notifications to user (the user is given the "text message" alert notification).
2. Session Based
- Apps may interact with peripherals while in the background
- scan for peripherals with services (not generic scanning)
- connect to peripheral
- exchange data with peripheral
- App MUST HAVE a "Start and Stop" user interface.
- Special Info.plist entry is need to get access to session-based mode.
- BUT be mindful of power usage.
However, I cannot seem to get the event-based model to work. Also, I would like to know if there is a way to adjust the message that the user gets, just like with localNotifications.
Anders
On Oct 26, 2012, at 9:51 AM, András Kovi < email@hidden> wrote:
Hi, you must add the bluetooth-central background mode. Otherwise your app is completely stopped. You won't receive disconnect or connect events either. Everything should start working correctly as soon as you add the flag.
Andras
On 2012.10.26., at 18:37, Anders Grunnet-Jepsen < email@hidden> wrote:
This question pertains to backgrounding:
I am trying to create an app where I will get a notification from the peripheral even when the app has been exited or suspended.
I cannot find any specific documentation on how to do this, which leads me to believe that it must be obvious.
I want to do EVENT BACKGROUNDING (as opposed to session backgrounding).
I am able to successfully tell the peripheral to notify me (with [p setNotifyValue:YES forCharacteristic:characteristic]) and
I do receive data in the "didUpdateCharacteristics" when the app is active.
However when I exit the app, I do not get an alert.
What am I missing? Do I need to tailor the alert somewhere or set up a local notification?
I have not added any backgrounding flags to the info plist as I understand that should not be necessary for Event Backgrounding.
Also, I am not closing the Bluetooth connection upon exiting the app, so the iPhone should be able to receive the notifications, even when suspended.
Is there some specific command that the peripheral has to send?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
==========================
Anders Grunnet-Jepsen, Ph.D.
CTO
ThinkOptics, Inc.
5568 Del Oro Dr.
San Jose Ca 95124
+1 765-88-WAVIT [765-889-2848] (Office)
+1 408 823 0930
fax: 408 431 Wavit
==========================
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
========================== Anders Grunnet-Jepsen, Ph.D. CTO ThinkOptics, Inc. 5568 Del Oro Dr. San Jose Ca 95124 +1 765-88-WAVIT [765-889-2848] (Office) +1 408 823 0930 fax: 408 431 Wavit ==========================
|