无意中发现在 iPad上 14.5 的版本,在蓝牙连接的回调中:
- (void) centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
如果打印 [peripheral description]。会看到有类似字符串 mtu = 23 ,其他版本未测试。 为了让我的发送数据更吻合这个MTU。
我处理一下这个字符串,读出这个值。
NSString *peripheralDescription = [peripheral description];
NSRange range = [peripheralDescription rangeOfString:@",[ ]+mtu[ ]+=[ 0-9]+," options:NSRegularExpressionSearch range:NSMakeRange(0, peripheralDescription.length)];
if (range.location!= NSNotFound) {
NSString *str = [peripheralDescription substringWithRange:NSMakeRange(range.location + 1, range.length-2)];
NSArray *array = [str componentsSeparatedByString:@"="];
self.mtu= [array[1] intValue] - 3;
NSLog(@"remoteDevice mtu = %d",self.mtu);
}
enjoy it!
|