Ios 我可以在AppDelegate.m中注销NSNotificationCenter吗?
我正在我的Ios 我可以在AppDelegate.m中注销NSNotificationCenter吗?,ios,objective-c,reachability,Ios,Objective C,Reachability,我正在我的AppDelegate.m中注册可达性通知,代码如下 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNetworkChange:) name:kReachabilityChangedNotificati
AppDelegate.m
中注册可达性通知
,代码如下
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleNetworkChange:)
name:kReachabilityChangedNotification
object:nil];
reachability = [Reachability reachabilityWithHostName:@"www.google.com"];
[reachability connectionRequired];
[reachability startNotifier];
我可以在AppDelegate.m中注销可达性通知程序吗
我正在尝试使用下面的代码注销可达性
-(void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
尝试将NotificationCenter addObserv代码放入
- (void)applicationDidBecomeActive:(UIApplication *)application {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleNetworkChange:)
name:kReachabilityChangedNotification
object:nil];
reachability = [Reachability reachabilityWithHostName:@"www.google.com"];
[reachability connectionRequired];
[reachability startNotifier];
}
并将其从:-
- (void)applicationWillResignActive:(UIApplication *)application
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
我应该在哪里使用这个?在AppDelegate.m或ViewController.m中?上述两种方法都是委托方法,请检入委托。m您只需将上述代码放入其中即可