我希望在我的应用程序被终止时调用一个方法。我不想在app delegate中执行它的主要问题,我想在我的视图控制器中调用该方法。 请帮帮我。
答案 0 :(得分:2)
试试这个
[[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
}];
答案 1 :(得分:0)
尝试通知方法
jhipster