0
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myReachabilityDidChangedMethod)
name:kReachabilityChangedNotification
object:nil];
Reachability *reachability;
reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
我上面的代码块在我的AppDelegate创建可达性的观察者,其目的是通过应用程序触发myReachabilityDidChangedMethod。观察员在AppDelegate的可达性不能触发
但是,我无法触发位于AppDelegate中的myReachabilityDidChangedMethod,当我打开或关闭我的wifi时,我在模拟器和ipad上都测试了它,但两者都没有任何响应。
不应该的可达性类本身自动发布通知? – Shing 2012-07-11 19:30:33
@Shing,不,它不会。用户必须在需要时明确向通知中添加项目。还要确保在应用程序退出时删除通知。使用此命令删除所有通知:'[[NSNotificationCenter defaultCenter] removeObserver:self];'或者删除特定通知:'[[NSNotificationCenter defaultCenter] removeObserver:self name:kReachabilityChangedNotification object:nil];' – Steven 2012-08-20 13:59:35