BabyBluetooth
BabyBluetooth copied to clipboard
建议大神空的时候,用新的xcode编译一下,把warning去掉
1.编译警告
1).This block declaration is not a prototype
- (BabyPeripheralManager *(^)())removeAllServices;
2).Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior...
虽然实际不会构成循环引用环,但是还是建议优化一下。
- (BabyPeripheralManager *(^)())stopAdvertising {
return ^BabyPeripheralManager*() {
[_peripheralManager stopAdvertising];
return self;
};
}
2.连接(或者取消)指定外设的时候,建议也加上超时检测。目前只有发现外设,自动连接的时候才检测超时。
//连接Peripherals
- (void)connectToPeripheral:(CBPeripheral *)peripheral{
[centralManager connectPeripheral:peripheral options:[currChannel babyOptions].connectPeripheralWithOptions];
//开一个定时器监控连接超时的情况
[connectTimer invalidate];
connectTimer = [NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(connectTimeout:) userInfo:peripheral repeats:NO];
}
3.BabyCallback 潜在的内存泄漏。
如果有多个channel,BabySpeaker 会持有 多个委托BabyCallback,但是目前只能切换 channel,也就是切换委托BabyCallback,但是没法销毁。一般委托的生命周期是跟着 监听者走的,建议在监听者销毁的时候 同时移除委托。具体可以主动调用;也可以通过运行时来做被动调用。