0
我想在应用程序终止时调用方法。我不想在应用程序委托中执行此操作,我想在视图控制器中调用该方法。 请帮我。我怎样才能得到应用程序将终止我的视图控制器中的委托?
我想在应用程序终止时调用方法。我不想在应用程序委托中执行此操作,我想在视图控制器中调用该方法。 请帮我。我怎样才能得到应用程序将终止我的视图控制器中的委托?
试试这个
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(applicationWillTerminate:)
name:UIApplicationWillTerminateNotification
object:[UIApplication sharedApplication]];
-(void)applicationWillTerminate:(NSNotification *)notify{
//do your task
}
或者
[[NSNotificationCenter defaultCenter]addObserverForName:UIApplicationWillTerminateNotification object:[UIApplication sharedApplication] queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
//do your task
}];
尝试通知方法
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(callOnApplicationTerminated:)
name:UIApplicationWillTerminateNotification
object:[UIApplication sharedApplication]];
thanx的答案..worked我 –