Skip to content

Instantly share code, notes, and snippets.

@SunXiaoShan
Created July 27, 2018 08:15
Show Gist options
  • Save SunXiaoShan/f1cc6c0f9d43bf9db2ee8a2432c3593c to your computer and use it in GitHub Desktop.
Save SunXiaoShan/f1cc6c0f9d43bf9db2ee8a2432c3593c to your computer and use it in GitHub Desktop.
- (void)peripheralManager:(CBPeripheralManager *)peripheral
didReceiveWriteRequests:(NSArray <CBATTRequest *>*)requests {
for (CBATTRequest *request in requests) {
if (request.value) {
NSString *value = [[NSString alloc] initWithData:request.value encoding:NSUTF8StringEncoding];
if ([_delegate respondsToSelector:@selector(BLEPeripheralComponentReceiveMessage:message:)]) {
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.delegate BLEPeripheralComponentReceiveMessage:self message:value];
});
}
[peripheral respondToRequest:request withResult:CBATTErrorSuccess];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment