![]() |
nRF5 SDK
v15.3.0
|
Choose documentation: | nRF5 SDK | S112 SoftDevice API | S132 SoftDevice API | S140 SoftDevice API | S212 SoftDevice API | S312 SoftDevice API | S332 SoftDevice API | S340 SoftDevice API |
Important: Before you run this example, make sure to program the SoftDevice.
The ANCS Client Application is an example that implements an Apple Notification Center Service client. This client receives iOS notifications and is therefore a Notification Consumer. It can be connected with a Notification Provider, typically an iPhone or some other Apple device, which functions as ANCS server. The application uses the GATT Service Client to look for an ANCS server whenever there is a change in the services on the peer device.
For detailed information about the Apple Notification Center Service, see Apple's iOS Developer Library.
When the application is connected to a Notification Provider, it receives and prints incoming notifications on the UART. Pressing Button 1 requests the attributes of the last received notification. For example, if the notification indicates a new email, notification attributes contain the app identifier, the title of the email, the actual message, the sent date, and so on. Pressing Button 2 requests the attributes of the app that sent the notification (currently, the app attributes contain only the name of the app). If any attributes are received, they are printed to the UART.
Notifications can have positive and negative actions associated with them, depending on the app that is sending the notification. For example, a notification for an incoming call is usually associated with the positive action to answer the call and the negative action to reject it. After receiving a notification, the available actions are indicated by flags on UART. Push Button 3 to perform the positive action as response to the notification, or Button 4 to perform the negative action.
You can find the source code and the project file of the example in the following folder: <InstallFolder>\examples\ble_peripheral\ble_app_ancs_c
Button assignments - in addition to those defined in BSP BLE Button Assignments:
Perform the following steps to test the ANCS Client Application with an iOS device (for example, an iPhone):
You can also test the application by emulating an iOS device with nRF Connect. To do so, perform the following steps (see the respective sections for detailed information):
<InstallFolder>\examples\ble_peripheral\ble_app_ancs_c
folder. Load the file ANCS_central.ncs
.The following table shows the format of a notification that you can send to the example application:
Field | Example value | Interpretation |
---|---|---|
Event ID | 0 | Notification added |
Flags | 18 | Positive/negative action |
Category | 06 | |
Category count | 02 | |
Notification UID | 01 02 03 04 | 67305985 (0x4030201) |
Notification Event: Added Category ID: Email Category Cnt:2 UID: 67305985 Flags: Positive Action Negative Action
The received notification has two flags: Positive Action and Negative Action. This means that you can perform these two actions on the notification.
The following table shows the format of the message that the application must send back to perform a notification action:
Field | Example value | Interpretation |
---|---|---|
Command ID | 2 | Perform notification action |
Notification UID | 01 02 03 04 | 67305985 (0x4030201) |
Action | 00 01 | Positive Negative |
The following table shows the relevant part of a request to retrieve notification attributes:
Field | Example value | Interpretation |
---|---|---|
Command ID | 0 | Get notification attributes |
Notification UID | 01 02 03 04 | 67305985 (0x4030201) |
Attribute ID | 00 | App identifier |
Attribute ID | 01 | Title |
Length | 20 00 | 0x0020 |
Attribute ID | 03 | Message |
Length | 20 00 | 0x0020 |
Note that the example application will request all existing attribute types, not only a subset.
The following table shows the format of a response that contains some of the requested notification attributes:
Field | Example value | Interpretation |
---|---|---|
Command ID | 0 | Get notification attributes |
Notification UID | 01 02 03 04 | 67305985 (0x4030201) |
Attribute ID | 01 | Title |
Length | 03 00 | 0x0003 |
Data | 6E 52 46 | "nRF" |
Attribute ID | 03 | Message |
Length | 02 00 | 0x0002 |
Data | 35 32 | "52" |
Attribute ID | 00 | App identifier |
Length | 03 00 | 0x0003 |
Data | 63 6F 6D | "com" |
Title: nRF Message: 52
App Identifier: com
With the app identifier, you can request attributes of the app that sent the notification.
The following table shows the format of a request to retrieve app attributes:
Field | Example value | Interpretation |
---|---|---|
Command ID | 1 | Get app attributes |
App identifier | 6D 6F 63 00 | "com" + '\0' |
Attribute ID | 0 | Display name |
The following table shows the format of a response that contains the requested app attributes:
Field | Example value | Interpretation |
---|---|---|
Command ID | 1 | Get app attributes |
App identifier | 63 6F 6D 00 | "com" + '\0' |
Attribute ID | 0 | Display name |
Length | 04 00 | 0x0004 |
Data | 4D 61 69 6C | "Mail" |
Display Name: Mail