Can an app receive bluetooth data if it is locked? - ios

Simply that question. You see other devices stating that they can, but built on older platforms. Any sample code would be great.

Yes, it is possible. You need to set UIBackgroundModes to "bluetooth-central" in info.plist file.
Note also, that Technical Q&A QA1657 in iOS Developer Library says the following
The External Accessory framework is designed to allow iOS applications to communicate only with hardware accessories that are developed under Apple's MFi licensee program. MFi compliant accessories can be implemented as wired devices, meaning they plug in to the iOS device's 30-pin connector, or as wireless devices, whereby they use Bluetooth as the communication channel. Either way, an application that uses the External Accessory framework will not be notified of an accessory's presence unless the accessory identifies itself as being MFi compliant, i.e., it was specifically designed to interface with an iOS application.
Developer reference also says that there is a Core Bluetooth framework for Low Energy devices in iOS5, but it's for Bluetooth 4.0 devices (BTLE) only, currently on the iPhone 4S.

Related

Can you obtain WiFi settings from iOS and pass it to a BLE device (similar to Withings)?

The Withings iOS app has the ability to obtain your wifi settings and pass it to the body scale via Classic Bluetooth (see screenshot below). From what I learnt it's a feature only available through the MFi program, which the Withings Scale is.
I'm building an app that talks to external BLE devices. Since MFi is not required for BLE devices, I'm wondering if there's a way to do the same thing with CoreBluetooth or other frameworks?
From Apple's MFi FAQ page:
"Accessories which connect to an Apple device using only Bluetooth Low
Energy/BTLE/Bluetooth 4.0 or standard Bluetooth profiles supported by
iOS are not part of the MFi Program."
Related question on ClassicBluetooth / MFi:
Can you pass WiFi settings from an iOS device to an ExternalAccessory object?

Bluetooth and iOS - what protocols/ profiles are supported?

I am developing an iOS bluetooth app that needs to pair with a peripheral device.
What frame work do I need to use to interact with a device that has support for the following protocols/profiles:
A2DP
HFP
HSP
Are either of these possible with an iOS device without being a member of the the MFI program?
How do I support these profiles:
https://support.apple.com/kb/HT3647
Do I do that using corebluetooth?
These are standard profiles that are supported inherently by iOS. You don't need to add any software to make the phone work with these. At the same time apps running on the phone will have limited access to what device they can use or are using but for example the audio routing can be obtained.
All in all, as long as the device implements the profiles correctly, any application will be able to use it, not just yours.
There are two completely different methods of doing Bluetooth communications. One is with the classic Bluetooth profiles and the latest is using BLE (Bluetooth Low Energy).
Classic Bluetooth can be used with the ExternalAccessory framework and GameKit framework.
BLE uses CoreBluetooth.
The classic profiles supported are listed here:
http://support.apple.com/kb/HT3647

How to use bluetooth classic instead of LE

In reference to Dennis Mathews answer how do you specify Bluetooth Classic instead of LE on iOS? Is there a different api from Core Bluetooth Framework?
Joels there is a very clear way to use Bluetooth classic on iOS. It is with the External Accessory framework (it also includes direct hardware connections in addition to Bluetooth classic however).
You need to add the ExternalAccessory.framework and specify "App communicates with an accessory" in the required background modes inside your plist to get started. It should be noted however that with Bluetooth classic, the user must add your Bluetooth device from the System Bluetooth settings. It is only with Bluetooth LE that we are able to add devices from the app side.
Check out the docs on the External Accessory Framework
In response to your question regarding the MFi program, this should clarify:
I want to develop an iOS app that communicates with an MFi accessory. Do I need to join the MFi Program?
No. iOS app developers do not need to join the MFi Program. Everything app developers need is in the External Accessory Framework,
which is provided in the iOS SDK. To access the iOS SDK, please join
the iOS Developer Program: https://developer.apple.com/programs/ios/.
If you'd like to learn more, consult the MFi FAQ
If your external accessory doesn't need high bandwidth in the connection to iOS, and you wish to use (or must use) 2.x/classic BT, (instead of 4.x/LE/Smart, which is very low bandwidth but requires no MFi dancing) you may be able to communicate by emulating a BT HID keyboard in your accessory.
It's hardly optimal, especially since the HID reverse channel is pretty limited (I think to things like lighting the caps lock key in the basic keyboard configuration (HID page 7 mapping, if I recall correctly.) OTOH, if your primary task is to push data to the iOS device, sending the data as keystrokes would not be too awful. (and might even be seen as virtue during testing :)
HID devices can declare additional capabilities in table defined keymaps, but I'm not sure if an iOS app can get at those alternate mappings with sanctioned APIs.

Connecting to a Bluetooth device from iOS, no MFi

The vibe I'm getting from Stackoverflow and the internet at large is that unless I'm using an LE device, any Bluetooth device I make for an iOS app must be MFi certified.
However, on the MFi FAQ page, I found this line:
...developers of accessories that rely solely on standard technology
(e.g., Bluetooth Low Energy or standard Bluetooth profiles) do not
need to join the MFi Program.
My device will be able to use the standard Bluetooth profile File Transfer Protocol (FTP).
Now this sounds like some conflicting advice to me, or perhaps I'm just not understanding correctly. So, having provided the above evidence, I'm just going to ask outright: Can I write and publish an iOS app that connects to a proprietary Bluetooth device using the standard Bluetooth profile FTP without certifying my device as MFi? And if so, what details, caveats, etc do I need to know?
The new Bluetooth 4.0 Low Energy (hereafter BLE 4.0) specification which is implemented in Apple's latest iOS devices does allow one to create app-specific profiles and connect to BLE 4.0 devices without jailbreaking, using an approved Bluetooth 2.1 profile, or becoming part of Apple'd MFI program and using the previously required MFI cryptographic chips.
In other words with the proper BLE 4.0 compatible bluetooth radios you can create wireless devices that connect to iOS apps without having the device pre-approved by Apple. However, you must write a custom app for the device, and Apple still holds the ability to reject that app if they want to. So they still control this to a great degree. This is essentially Apple's answer to the Android ADK, while not fully relinquishing the ability to shut down apps and devices they don't like.
Your app must include specific XML schema for your app's bluetooth profile, and use CoreBluetoothFramework APIs, so it's very obvious to Apple during the app approval process that your app connects to a device. If your app does not work without the device present, then it's likely to be rejected if you are not part of the MFI program, as Apple cannot test the app without your device. The apps that appear to be successful in passing this test use the device as an accessory to app functionality, rather than a requirement. For instance an exercise app might connect to a BLE 4.0 heart rate monitor, but the app doesn't depend on it.
Some apps seem to be getting around this by displaying simulated, or online information in place of the device information when no device is present. Thus the app can be tested without the device, and functionally works when the device is present.
You can find out some successful efforts online:
http://blog.makezine.com/2012/03/19/bluetooth-4-0-from-arduino-to-iphone-no-jailbreaking-no-mfi/
BlueGiga in particular has been pushing their devices specifically for this use, so there are probably forums and support for this elsewhere.
Keep in mind that the devices that currently support BLE 4.0 are limited, and currently only include
iPhone 4S and later iPhones
recent MacBook Air, Mac Mini
iPad (3rd generation and later, and iPad mini)
Macbook Pro Retina
There may be other Apple devices that support this standard, it's something Apple is advertising openly on each product's technical specifications page so it's easy to find for current products.
That line is referring to standard profiles supported natively by ios devices, such as HFP or A2DP. If you build a headset device that does HFP, the iphone will be able to connect to it and route your call to the headset without the headset being part of MFi.
If you want to write an app that does other things with bluetooth, inlcuding FTP, you would have to use MFi.

Is it possible to develop an iOS app with bluetooth capabilities?

Would the following be possible?
Let's say I have a scale with Bluetooth capabilities, when I turn it on, it sends the weight via BT.
Is it technically possible to develop an iOS app which pairs with the scale and receives the data from it?
According to Apple:
Technical Q&A QA1657: Using External
Accessory framework with Bluetooth
devices.
Q: I understand that the External Accessory framework in iOS 3.0 and later will allow my application to communicate with Bluetooth devices. So why doesn't my application see the Bluetooth accessory sitting next to my iPhone?
A: The External Accessory framework is designed to allow iOS applications to communicate only with hardware accessories that are developed under Apple's MFi licensee program. MFi compliant accessories can be implemented as wired devices, meaning they plug in to the Apple device's 30-pin or Lightning connector, or as wireless devices, whereby they use Bluetooth as the communication channel. Either way, an application that uses the External Accessory framework will not be notified of an accessory's presence unless the accessory identifies itself as being MFi compliant, i.e., it was specifically designed to interface with an iOS application.
Yes, we can connect Bluetooth devices with iOS application through Core bluetooth framework. This framework is supported on the iPhone 4s, iPhone5,iPhone 5S ,iPad3. We can use BLE 4.0 for the communication between scale and iOS application. Here, iOS application become the client and scale become the peripheral. You Can set as well as get data from the weighing scale.
While the External Accessory Framework with Bluetooth is one of the possible solutions, it has additional requirements to be built as per Apple MFi, here Bluetooth reference is to the Classic Bluetooth (Version 3.x and below)
The best solution for the use case you have defined is to use the Bluetooth Low Energy (LE) (aka Bluetooth Smart) technology (Bluetooth 4.0) and it is available to applications as part of the Core Bluetooth Frameworks
Here are the APIs for Core Bluetooth that applications can use.
While currently Bluetooth Low Energy is supported on the latest iPhone 4S, New Mac Mini & Macbook Air - its expected most new Apple & Others hardware will have this standard.

Resources