---
title: "NotifiCationCenter控制使用"
author: "zcw_java"
date: "2013-07-02T11:31:48Z"
tags: []
categories: ["移动开发"]
slug: "notificationcenter"
draft: false
lastmod: "2013-07-02T11:31:48Z"
id: 1897309
url: "https://zcw-java.iteye.com/blog/1897309"
---

NSNotificationCenter

第一种，这个只是传值，通过NSNotification获取，当然也可以直接使用obj

注册A

```c++

[[nsnotificationcenter defaultcenter] addObserver:self selector:@selector(enableOrDisableAudio:) name:@"enableOrDisableAudio" object:nil];
- (void)enableOrDisableAudio:(NSNotification *)notification
{
    printf("enableOrDisableAudio\n");
    BOOL bIsEnableAudio = [[notification object] boolValue];
    self.m_bIsEnable = bIsEnableAudio;
    
    [self enableaudio:bisenableaudio];
}

```

响应B

```c++

NSNumber *boolNum = [nsnumber numberwithbool:m_bisspkon];
    [[nsnotificationcenter defaultcenter] postNotificationName:@"enableOrDisableAudio" object:boolNum];

```


第二种多值传输（obj）
注册A

```java

[[nsnotificationcenter defaultcenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object: nil];

- (void)reachabilityChanged:(NSNotification *)note
{
	Reachability *curRech = [note object];
	NetworkStatus status = [currech currentreachabilitystatus];
    
	if (status == NotReachable)
	{
        [self setstatusbartoshow];
        [svstatushud showwithmessage:localized(@"disconnect from network") duration:kshortduration];
	}
	else
    {
        [self resetstatusbarblank];
    }
    
}

```

响应B

```c++

Reachability* noteObject = (Reachability*) info;
	// Post a notification to notify the client that the network reachability changed.
	[[nsnotificationcenter defaultcenter] postNotificationName: kReachabilityChangedNotification object: noteObject];

```


数组传输,注意响应消息的userInfo一定是NSDictionary类型

```c++

- (void) keyboardWillShow:(NSNotification *)aNotification
{
        NSDictionary *userInfo = [anotification userinfo];
}

```