NSNotification带参数

来源:互联网 发布:知乎live过期收听购买 编辑:程序博客网 时间:2024/06/05 18:37


发送通知

[[NSNotificationCenter defaultCenterpostNotificationName:OTAUpdatingNotification

 object:characteristic];


接受通知

[[NSNotificationCenter defaultCenteraddObserver:self selector:@selector(OTAUpdating:) name:OTAUpdatingNotification object:nil];


接受通知の处理

-(void)OTAUpdating:(NSNotification *)notification

{

    CBCharacteristic *characteristic = [notification object];

    NSData *Data = characteristic.value;

    // DataString

}




1、带参数


//注册通知//方法实现

    [[NSNotificationCenter defaultCenteraddObserver:self selector:

@selector(updatCardInfo:) name:updateCardInfoNotification object:nil];


//方法实现

-(void) updatCardInfo :(NSNotification*) notification

{

    接收参数 = [notification object]; //通过这个获取到传递的对象 

}

//发送通知

   [[NSNotificationCenter defaultCenterpostNotificationName:

updateCardInfoNotification object:参数];




2、不带参数

//注册通知

    [[NSNotificationCenter defaultCenteraddObserver:self 

selector:@selector(deviceDamage) name:VDBlueToothDamageNotification 

object:nil];

//方法实现

-(void)deviceDamage

{

}

//发送通知

   

 [[NSNotificationCenter defaultCenterpostNotificationName:

VDBlueToothDamageNotification object:nil];


0 0