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我 –