Can I implement an iOS App to act as a Bluetooth low energy service?
I need to be able to programmatically define:
a service UUID
characteristics for the service
a way to update the values of these
a way to define the user permission of the characteristics: read / write / notify
a way to define the transmission (TX) power of the service
Would appreciate if you could point me out to a good demo / example to get started or even share some code snippet so this can become part of the Documentation of iOS.
Read the Core Bluetooth guide as throughly as possible, especially setting up a Peripheral Service:
https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/AboutCoreBluetooth/Introduction.html#//apple_ref/doc/uid/TP40013257-CH1-SW1
Keep in mind that if you are looking to adjust these parameters you need to pay attention to how iOS changes the BLE data structure being emitted when in background mode / inactive state.
Related
I have a very specific task - I need to find a way to observe iOS device temperature. I'm developing an application which is a system for multiple devices. And sometimes there're cases when one of iPhones/iPads is overheating. My task is simple - I need to have a possibility to tell other devices that one certain "chain" is about to overheat or already overheated.
Is there any way to do this without violating Apple security laws? Because this application will go to Appstore and I don't want to have problems at this stage.
You can do it by using Bluetooth Low Energy by following way:
1. Create a characteristic and service for reading temperature.
Add the listener on other devices so that they will get notify when temperature of the device will change.
For overheated, define a threshold.
For temperature, please refer: https://github.com/beltex/SystemKit/blob/master/SystemKit/Battery.swift
For BLE, please refer https://www.appcoda.com/core-bluetooth/
I am trying to build an app that is able to detect another iPhone with the same app within a certain proximity. I don't want to use location. Is this possible?
Assuming you're looking for devices pretty close to each other, generally on the order of a single room, maybe a bit further if you're lucky (sometimes quite a lot less if you're not), what you're looking for is Bluetooth LE (Low Energy).
Choose a service UUID (type uuidgen from the commandline; it'll make you one)
Using CBPeripheralManager, advertise your service ID (see startAdvertising)
Using CBCentralManager, search for the same service ID (see scanForPeripherals)
Register yourself as a background Bluetooth app, both as bluetooth-central and bluetooth-periphral (see Core Bluetooth Background Execution Modes for details)
With this setup, your app will advertise your service, and your app will automatically be launched anytime the phone sees something advertising the service.
See the Core Bluetooth Programming Guide for details. Bluetooth development is a bit finicky and there are lots of little corner cases you often need to deal with, but the basics are pretty straightforward, especially for this kind of use case.
If you just want to find people who are actively (in the foreground) using your app and communicate with them, take a look at GameKit. It's built on top of Core Bluetooth, but does a ton of the work for you. It's especially designed for getting people together to play games, but it can do a lot more than that.
One note: Do not confuse Bluetooth with Bluetooth LE. They are radically different and basically unrelated protocols. Bluetooth is used for things likes streaming music, and you have basically no access to it at all in iOS. BLE is used for exchanging small bits of data with low-power peripherals like heart rate monitors and the like. Core Bluetooth only deals with BLE.
You could also use iBeacons for this (An abstraction on top of BLE). iBeacons are a little easier to use than BLE, and like Core Bluetooth you can set up beacon region monitoring so your app will get launched if a beacon (or group of beacons) you are listening for comes into range. (But beacon monitoring uses the location manager)
Is it possible to simultaneously broadcast my iOS app as an iBeacon and at the same time publish a service?
My app currently advertises a service, which works perfectly fine. My client app (central) is able to find the peripheral, connect, obtain the service and read data from the characteristic. However, if I update my server app (peripheral) to start broadcasting as an iBeacon emitter in addition to the service, I am no longer able to find services that I setup to advertise on the client app (central).
The idea of this is that I want to be able to read information from the server (peripheral) app when in close proximity from the client (central).
Is this technically feasible?
I was thinking about turning off iBeacon transmission when a device comes into close proximity and then starting the service broadcast, but there is no API in Core Bluetooth that calls back to the emitter when a client device enters the region being advertised.
Is this doable? Is there a workaround that would achieve something along these lines? I would like to avoid any networking, as this should be an offline solution.
Taz, For sure you can be an iBeacon and you can look for iBeacons. What I did and what I see other doing is combining iBeacons with other services, such as the CloudKit [which yes, means networking too] to add functionality to their basic functionality.
That said I can imagine an app in which your iBeacons switch to a different protocol when they see each other, the challenge; how-to negotiate a channel/UUIDs for a BLE peripheral/central pair.
I am still in the process of building, but have implemented something similar over the past months... in short you hardcode an initial channel to start your BLE conversation, your first and only exchange on said channel being to agree a new BLE one to use.
I would like to create a very simple app. When 2 peoples (who got the app) are geographically very close (20-30-40 meters), the 2 automatically receive a push notification with some infos about the other person. First, is it technically possible ? What would the most efficient way to make it ? Ibeacons ? Bluetooth ?
You can probably do something like what you are describing, however you can't solve it with iBeacon alone, that would just be a single component in the system.
The main parts of the system would be
Mobile app
Physical iBeacons (to let you know when you are close by)
Backend web service (to coordinate between the app)
When a user with your App comes within range of an iBeacon you could have it call up to the web service and provide the iBeacon identifiers. Then you could use that information on the back end to see if another device was also recently with in range. If so, push out a notification.
Just be conservative on your expectations. This would require a number of moving parts, and you should become familiar with the limitations of how iOS background notifications and how iBeacons work.
I'm looking for a way to be able to track another BTLE-enabled iOS device using mine, while within range. Basically, one device would have to log it's geolocation info, and then send it periodically to the other device, using BTLE.
How would I be able to do this? In general, I haven't been able to find much info on how to send and receive messages via BTLE, so any help in that category would be great. I've seen this answer already, but it didn't help me much, and I'm wondering if anything has changed since then.
If not possible through Apple's built-in framework, do you know of any external ones that would allow for this?
Long, long, long, longgg story short, but here ya go:
On one iOS device, adopt both the CBCentralManager and CBPeripheralManager. The CBCentralManager is responsible for connecting to external peripherals and maintaining that connection. The CBPeripheralManager will be what you'll use to read/write from the iOS device that your using a peripheral.
On the other iOS device, adopt just the CBPeripheralManager. You'll need add all the services and characteristics into the CBPeripheralManager that are stated in the GATT profile. Check out developer.bluetooth.org. These services and characteristics are necessary in order to connect from one device to the other.
In addition to just the gatt characteristics and services, you'll need to add in a custom service with a characteristic that you store your location data.
Check out the docs but for CBPeripheralManager in particularly you'll need to utilize
-(void) peripheralManager:(BLEPeripheralManager*)mgr requiresResponseToWriteRequests:(NSArray*)requests;
and
-(void) peripheralManager:(BLEPeripheralManager*)mgr requiresResponseToReadRequest:(CBATTRequest*)request;
in order to pass the location data between devices..Sorry for the brief overview, but there's just way too much to write up quickly.