Created
July 27, 2018 07:59
-
-
Save SunXiaoShan/bb5768fe703fa8a084f3ce25df33a5b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)setupService { | |
// Step 1: Create CharacteristicUUID | |
CBUUID *characteristicUUID = [CBUUID UUIDWithString:kCharacteristicUUID]; | |
CBMutableCharacteristic *characteristicM = [[CBMutableCharacteristic alloc] | |
initWithType:characteristicUUID | |
properties:CBCharacteristicPropertyNotify | | |
CBCharacteristicPropertyRead | | |
CBCharacteristicPropertyWrite | | |
CBCharacteristicPropertyWriteWithoutResponse | |
value:nil | |
permissions:CBAttributePermissionsReadable | | |
CBAttributePermissionsWriteable | |
]; | |
self.characteristicM = characteristicM; | |
// Step 2: Create CBMutableService | |
CBUUID *serviceUUID = [CBUUID UUIDWithString:kServiceUUID]; | |
CBMutableService *serviceM = [[CBMutableService alloc]initWithType:serviceUUID primary:YES]; | |
[serviceM setCharacteristics:@[characteristicM]]; | |
// Step 3: Add Service to Peripheral Manager | |
[self.peripheralManager addService:serviceM]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment