我如何获得应用程序将终止我的视图控制器中的委托?

时间:2017-02-27 05:15:25

标签: ios objective-c

我希望在我的应用程序被终止时调用一个方法。我不想在app delegate中执行它的主要问题,我想在我的视图控制器中调用该方法。 请帮帮我。

2 个答案:

答案 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