Communicating with a Bluetooth Classic device in iOS when the app is in the background? - ios

I'm working on iOS development for a bluetooth peripheral. We want the (already paired) device to connect when a button is pressed on it, and this will cause the app to execute some code. Is it possible for the app to detect that the device is connected, even while in the background?
Also, is it possible for the app to bring itself into the foreground when this is detected? Would I need to be a member of the MFi program to do either of these things?

You will be able to detect that the device is connected in the background using Bluetooth 2.0, however you must include the App communicates with an accessory string under Required Background Modes in the app's plist.
So yes, the first part of your question is doable. However when you say: "We want the (already paired) device to connect when a button is pressed on it", it is important to note that this functionality must be built into the device's firmware. The app can always be searching for it, but the device will not be able to communicate with the phone until it connects. Therefore, the button must wake up the device and signal that it now wants to connect.
For the third part of your question, you will not be able to bring the app into the foreground without the user opening the app.
Btw, CoreBluetooth is the Bluetooth Low Energy framework for iOS. It is completely different from Bluetooth 2.0.

as ttarules told you iphone can't connect automaticly to a paired device.
I don't know what kind of bluetooth receiver have you in your device but generally you can set up a method of "AUTOCALL" that automatically call a paired device (in this case an iPhone).
When you (your iPhone) come around the device it automatically establish a connection!
If you set all the parameters correctly in the bluetooth module you can make sure that the iPhone shows a message like this: "YourDevice would like access to YourApplication" when the connection is established.
this way helps the user to use your application and you can run the code you mentioned above when the app start.

Related

CTKD implementation issue on iOS

I am working on an audio device project with dual-mode Bluetooth. I want to create a seamless connection experience with iOS devices, so I use CTKD with iOS. This gives us the ability to connect both BR/EDR and BLE without leaving our app in the system settings.
It works perfectly if the initial pairing happened inside the app. I got both BR/EDR and BLE connected and working and only one device shows on the Bluetooth page.
But if I pair the Bluetooth(BR/EDR) first in the system settings and then go to the app to pair BLE. The app initiated a new CTKD process, which creates a new BLE connection beside the BR/EDR connection.
My question is if I pair BR/EDR first in the Bluetooth settings, is there a way that I can only pair BLE and didn't trigger the CTKD while keeping the one device displayed on the Bluetooth settings page? Or anything else that can get the same result?

How to save a bluetooth connection to settings using CoreBluetooth and Swift

I have a device I want to keep connected to my iPhone while the app I'm building is not running. Currently, I'm at the point where I connect to the bluetooth device, hop over to settings, and can see the device there (I'm using the Nordic Thingy for testing).
I know it is possible because I have a Bose app that does the same thing with my headphones: it doesn't need me to have the app open or even in the background for the headphones to work after I've connected to them via the app.
I've looked into how to persist the bluetooth connections with my team, but we've only found guides similar to this one on how to save data in the background for autoconnection when the app is open again, or guides on how to work with bluetooth devices when your app is in the background.
Is there a way to mimic Bose's behavior here?

Ios Application connected in Background with device

i have an application that is connected with a chip by bluetooth.
Device and phone are constantly connected to calculate the distance between them by bluetooth delay in reply.
App is working fine in foreground.
When i go background the app is still running, but cannot connect to the device.
I already tried to fix with this guide: Core Bluetooth Programming Guide
but i didnt made it.
Some suggestion?
You need to introduce more detail.
Your app will not run in background mode even bluetooth connection is on.
But your app still have a chance to execute some code in a short time if some bluetooth event happen.
Connection lost.
Notification received.
If your application work like anti-loss bluetooth tag, you need
Enable background in iOS app.
Write your code in core bluetooth delegate.
And One reminder: Calculate distance based on bluetooth relay is not smart. Bluetooth communication is not designed to support this kind of feature.
It work on license free 2.4G band and human body has big impact on it.

iOS/Swift : Automatically Pair With Bluetooth Classic Device

We are building a custom Bluetooth device that supports both Bluetooth Classic for Handsfree as well as Bluetooth LE for other features. I am able to connect and communicate with the device via Bluetooth LE however, right now the user must manually pair with the device from Settings in order for the handsfree stuff to work. Like the Apple Watch, is it possible to automatically pair with the device via Bluetooth Classic when the device is selected from the Bluetooth LE list of available devices?
Basically, here is how we want it to work.
User launches application for the first time.
User is redirected to registration screen and registers their phone with our environment.
User is taken to the applications Dashboard and then clicks the applications Settings button.
In Settings, the user clicks Bluetooth Peripherals and is taken to a screen with a list of the BLE devices in range.
Here is where the new magic needs to happen:
User chooses BLE device, the devices is discovered and connected to via BLE.
After the devices characteristics have been discovered, the application should pair with the device via Bluetooth Classic for the handsfree stuff to work such as the microphone and speaker.
Any help is appreciated.
I have looked into the External Accessory framework however, I was unable to get it to even work properly. The application kept failing telling me "init" was not available or something.
Thank you.
We're trying to do the same thing and it looks like you can only pair a hands-free device working via HFP profile if leaving your app, going to Bluetooth settings in Settings.app and tapping the device there. From the app it's absolutely impossible. All the hands-free vendors I checked recently (Jabra, Parrot, etc.) do it this way.
The only thing I can think about would be pair via BLE, send the iPhone name to your hands-free accessory via BLE open Bluetooth settings screen in the Settings.app and wait for the accessory to discover the iPhone and connect to it from its side. This will save your user a tap, but he will still have to open the Settings.app (manually, bloody hell, not even via a system alert).
ExternalAccessory.framework is used to connect with devices registered in MFi program. It has absolutely nothing to do with hands-free devices working with HFP profile.

iOS: Automatically reestablishing Bluetooth BLE connection when in range

Is is possible to "pair" a Bluetooth BLE device such that they automatically connect when in range? (ie. an iPhone app sets up a connection to the Bluetooth device and from then on, the iPhone automatically reconnects to the device if in range, even if the app hasn't been opened in days and is fully closed).
Once reconnected, the device could either using Event Backgrounding to prompt the user to open the app or otherwise interact with a possibly backgrounded app (as described here).
Anecdotally, I've used Bluetooth keyboards that automatically reconnect to my laptop when back in range. These are not necessarily BLE devices, is this something that's possible in BLE land?
Could this be possible if the iPhone were the server instead of the device? What if this were done using traditional Bluetooth under the MFI program?
There are number of relevant comments here and on the Apple Bluetooth-dev mailing list, but nothing that cleared it up for me. Thank you for your help.
I posted my question on Bluetooth-dev, I'm leaving the response here for posteriority: http://lists.apple.com/archives/bluetooth-dev/2012/Sep/msg00117.html

Resources