2017-02-27 48 views

回答

1

試試這個

[[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 
    }]; 
+0

thanx的答案..worked我 –

0

嘗試通知方法

[[NSNotificationCenter defaultCenter] 
        addObserver:self 
         selector:@selector(callOnApplicationTerminated:) 
          name:UIApplicationWillTerminateNotification 
          object:[UIApplication sharedApplication]]; 
相關問題