设备连接到wi-fi时的iOS post通知

设备连接到wi-fi时的iOS post通知,ios,networking,notifications,Ios,Networking,Notifications,当设备连接到wi-fi或移动数据网络时,我是否有办法自动发布通知 我在想,当连接发生时,在我的应用程序委托中使用这个: [[NSNotificationCenter defaultCenter] postNotificationName:@"connectedToNetwork" object:nil]; 在我的课堂上,要捕获此通知: [[NSNotificationCenter defaultCenter] addObserver:self

当设备连接到wi-fi或移动数据网络时,我是否有办法自动发布通知

我在想,当连接发生时,在我的应用程序委托中使用这个:

[[NSNotificationCenter defaultCenter]
 postNotificationName:@"connectedToNetwork"
 object:nil];
在我的课堂上,要捕获此通知:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(doSomething)
                                             name:@"connectedToNetwork"
                                           object:nil];
我正在使用可达性来查看设备是否连接到internet,但这不是我想要的。我希望在设备连接到wi-fi或移动网络时自动调用一些通知。我不在乎是否可以通过该网络访问互联网,我只需要在连接发生时得到通知

// allocate a reachability object
Reachability* reach = [Reachability reachabilityWithHostname:@"www.google.com"];

// tell the reachability that we DONT want to be reachable on 3G/EDGE/CDMA
reach.reachableOnWWAN = NO;

// here we set up a NSNotification observer. The Reachability that caused the notification
// is passed in the object parameter
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(reachabilityChanged:) 
                                             name:kReachabilityChangedNotification 
                                           object:nil];

[reach startNotifier]