发送通知
[[NSNotificationCenter defaultCenter] postNotificationName:OTAUpdatingNotification
object:characteristic];
接受通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(OTAUpdating:) name:OTAUpdatingNotification object:nil];
接受通知の处理
-(void)OTAUpdating:(NSNotification *)notification
{
CBCharacteristic *characteristic = [notification object];
NSData *Data = characteristic.value;
// Data转String
}
1、带参数
//注册通知//方法实现
[[NSNotificationCenter defaultCenter] addObserver:self selector:
@selector(updatCardInfo:) name:updateCardInfoNotification object:nil];
//方法实现
-(void) updatCardInfo :(NSNotification*) notification
{
接收参数 = [notification object]; //通过这个获取到传递的对象
}
//发送通知
[[NSNotificationCenter defaultCenter] postNotificationName:
updateCardInfoNotification object:参数];
2、不带参数
//注册通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(deviceDamage) name:VDBlueToothDamageNotification
object:nil];
//方法实现
-(void)deviceDamage
{
}
//发送通知
[[NSNotificationCenter defaultCenter] postNotificationName:
VDBlueToothDamageNotification object:nil];