How to use service soliciting with IOBluetooth/CoreBluetooth?
Asked Answered
S

1

1

What I'm trying to do is use the Apple Notification Center Service (ANCS) from my iPhone on my Mac. To make my Mac show up on in my iPhone's Bluetooth settings, I apparently need to use service soliciting.

What I've tried so far is initiate a CBPeripheralManager on my Mac, add the ANCS service to it and start advertising. That doesn't seem to do it, as my Mac doesn't show up in my iPhone's Bluetooth settings. What I've also tried is initiate a CBCentralManager and start scanning, with the ANCS UUID in the CBCentralManagerScanOptionSolicitedServiceUUIDsKey key, which doesn't work either.

Does anyone have an idea on how to accomplish this? I've spent tons of hours watching WWDC videos and browsing through Apple's documentation, but other than some vague mentions of "service soliciting", I can't find it.

Thanks!

Sternutation answered 5/5, 2014 at 9:30 Comment(4)
I was playing around with this a week or so ago, and I couldn't get the iPhone to advertise the ANCS UUID unless I was running an app that advertised another (any other) BLE service. This doesn't seem right to me, but it is what I found - Hopefully someone else can offer some answer/insightsTichon
I guess KhaosT has shared exactly the code you are looking for github.com/KhaosT/ANCS-Mac There are many other implementations too.Congelation
@Tichon there is no other way than having an app advertising on the phone. iOS automatically solicits ANCS and ANCS is not accessible in other ways. You were doing it right. You can use any app, e.g. LightBlue for advertising. The advertisement content doesn't matter at all.Congelation
I've been trying to do this myself. This whole "Service Solicitation" thing is an elusive 1. Here's what I know so far: 1) iOS-iOS ANCS can't work (reportedly verified by someone at Apple), 2) OSX-iOS ANCS works, but you need an app on iOS advertising some other service until ANCS can be seen by OSX, 3) "Service Solicitation" works, but I haven't come across anyone who's done it on OSX (here's an embedded device example - you'll find hints about the structure of the Service Solicitation advertising packets)Schizophrenia
C
6

When a Bluetooth LE device advertises, it contains certain data in its advertising packet. This can overflow into what is known as Extended Inquiry Response (EIR) data, which the scanning device can request.

To use service solicitation, one has to include the key 0x15 (marking "List of 128-bit Service Solicitation UUIDs, see here) and the ANCS UUID 7905F431-B5CE-4E99-A40F-4B1E122D00D0.

I have been able to get this to work on embedded platforms and iOS but have not tried it on OSX. However, you should be able to request the system to add the advertising data in by using the key you mentioned above:

CBCentralManager *manager = [[CBCentralManager alloc] initWithDelegate:self 
                                                                 queue:nil];
[manager scanForPeripheralsWithServices:nil
                                options:@{
    CBCentralManagerScanOptionSolicitedServiceUUIDsKey:@[
        [CBUUID UUIDWithString:@"7905F431-B5CE-4E99-A40F-4B1E122D00D0"]]}];

This passes a dictionary containing that key paired with an array of a single CBUUID object for the ANCS UUID.

Counterproof answered 7/5, 2014 at 19:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.