somasekhar
somasekhar

Reputation: 313

iOS Core Bluetooth ANCS With External BLE Device

I am working an iOS application which interacts with external BLE accessory (cc256x) using CoreBluetooth. I have to send iOS notifications from iOS device to BLE device. As per Apple documentation I am using ANCS (Apple Notification Center Service).

https://developer.apple.com/library/ios/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/Introduction/Introduction.html

The steps which I followed from iOS App are:

iOS device acts as a peripheral and advertises ANCS like below.

-(void)addService
{
    CBUUID *notificationSourceUUID = [CBUUID UUIDWithString:@"9FBF120D-6301-42D9-8C58-25E699A21DBD"];

    CBMutableCharacteristic *notificationSourceCharacteristic = [[CBMutableCharacteristic alloc] initWithType:notificationSourceUUID properties:CBCharacteristicPropertyNotify value:nil permissions:CBAttributePermissionsReadable];

    CBUUID *controlPointUUID = [CBUUID UUIDWithString:@"69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9"];

    CBMutableCharacteristic *controlPoint = [[CBMutableCharacteristic alloc] initWithType:controlPointUUID properties:CBCharacteristicPropertyWrite value:nil permissions:CBAttributePermissionsWriteable];

    CBUUID *dataSourceUUID = [CBUUID UUIDWithString:@"22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB"];

    CBMutableCharacteristic *dataSource = [[CBMutableCharacteristic alloc] initWithType:dataSourceUUID properties:CBCharacteristicPropertyNotify value:nil permissions:CBAttributePermissionsReadable];

    CBUUID *newAlertCategoryUUID = [CBUUID UUIDWithString:@"0x2A47"];

    CBMutableCharacteristic *newAlertCategoryChar = [[CBMutableCharacteristic alloc] initWithType:newAlertCategoryUUID properties:CBCharacteristicPropertyRead value:nil permissions:CBAttributePermissionsReadable];

    CBUUID *supportedUnreadAlertCategoryUUID = [CBUUID UUIDWithString:@"0x2A48"];

    CBMutableCharacteristic *supportedUnreadAlertCategoryChar = [[CBMutableCharacteristic alloc] initWithType:supportedUnreadAlertCategoryUUID properties:CBCharacteristicPropertyRead value:nil permissions:CBAttributePermissionsReadable];

    CBUUID *newAlertUUID = [CBUUID UUIDWithString:@"0x2A46"];

    newAlertChar = [[CBMutableCharacteristic alloc] initWithType:newAlertUUID properties:CBCharacteristicPropertyNotify value:nil permissions:CBAttributePermissionsReadable];

    CBUUID *unreadAlertUUID = [CBUUID UUIDWithString:@"0x2A45"];

    unreadAlertChar = [[CBMutableCharacteristic alloc] initWithType:unreadAlertUUID properties:CBCharacteristicPropertyNotify value:nil permissions:CBAttributePermissionsReadable];

    CBUUID *alertNotificationControlPointUUID    = [CBUUID UUIDWithString:@"0x2A44"];

    self.alertNotificationControlPointChar = [[CBMutableCharacteristic alloc] initWithType:alertNotificationControlPointUUID properties:CBCharacteristicPropertyWrite value:nil permissions:CBAttributePermissionsWriteable];

    ANCSUUID = [CBUUID UUIDWithString:@"0x1811"];

    CBMutableService *ANCS = [[CBMutableService alloc] initWithType:ANCSUUID primary:YES];

    ANCS.characteristics = @[newAlertCategoryChar,supportedUnreadAlertCategoryChar,newAlertChar,unreadAlertChar,self.alertNotificationControlPointChar,notificationSourceCharacteristic,controlPoint,dataSource];

    [self.peripheralManager addService:ANCS];
}


- (void) advertiseANCS
{
    NSLog(@"%s", __FUNCTION__);

    [self addService];

    // define the Advertisement data
    NSMutableDictionary *advertisementData = [NSMutableDictionary dictionary];
    [advertisementData setValue:@"ANCS" forKey:CBAdvertisementDataLocalNameKey];
    [advertisementData setValue:@[ANCSUUID] forKey:CBAdvertisementDataServiceUUIDsKey];

    [self.peripheralManager startAdvertising:advertisementData];
}

Services are advertising and external cc256x based device which acts as a central are able to scan and connect to peripheral.

When cc256x device trying to subscribe notifications for new alerts/unread alerts they are getting error as:

Error - ANS_Decode_Un_Read_Alert_Status_Notification returned -1004.

The error suggests that the remote app has sent a wrong/corrupted "Unread Alert Status Notification Behavior" notification.

As far as my understanding from iOS app we have to just advertise ANCS, once BLE device subscribed to ANCS characteristcs,iOS automatically sends notifications.

I tried as mentioned in this link

iOS 7 ANCS: Discovering the primary ANCS Service UUID

but not able to see notifications in BLE peripheral.

Is there anything am missing? Please help me out as am not able to find solution to this.

Upvotes: 1

Views: 1041

Answers (0)

Related Questions