This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to setup "Immediate Service alert client" iOS

How do you setup "immediate Service Alert" Client on iOS, in order to get notified when an action is taken on the bluetooth peripheral ? (eg. Button press)

  • Hi Raphael, thanks for getting in touch!

    You can use the nRFToolbox app as an implementation guide, the service UUID you're looking at is available on this line here with the UUID of 1802

    ###First way: Event from phone to peripheral, AKA "Find me"

    You'll need to start scanning for this service identifier, general scanning procedure can be seen here, simply replace the service identifier with the one you're targeting.

    after connecting and getting the peripheral, follow the service discovery procedure found here

    and after getting the targeted service, discover it's characteristics as done here

    Now you're almost set, when the characteristic is discovered, hold a reference to it, as a class properties for example, you can see how we do that here

    and when you tap the button on your phone, or call the "Find me" method, this will write to the characteristic the values you can see here, to trigger the event on the peripheral, this will usually make the peripheral play a sound or do any other predefined action.

    ###Second way: Event from peripheral to phone ###(This answers your question)

    if you want to do things the other way, you need to reverse the roles, you need to create a class that has a CBPeripheralManagerproperty and implements the CBPeripheralManagerDelegate, those methods are referenced here

    After that you need to implement the immediate alert service on your own "peripheral" (your iPhone in this case), seen at this step

    You also need to add the Alert level characteristic into the service with UUID 2A06

    Once you have that in place, pressing the button on your BLE device will trigger the delegate method: peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest])

    You can see the full body of the function here to see how the data is parsed and how to take action depending on type of event.

    Here is the reference to the immediate alert service for future reference

    This should set you on the right path, if you have any other issues, don't hesitate to ask!

  • Thank you very much for this detailed answer ! Now everything makes sense!

  • No problems, glad to help !, remember to mark as solved if it worked for you so people coming from google searches see that this has a solution :) thanks!

Related