title: Why viewWillDisappear or viewDidDisappear not called when app quit in iOS simulator?
body: <p>I'm trying to call <strong>removeObserver()</strong> when the app quits. But when I used <strong>NSLog()</strong> to check, I found neither <strong>viewWillDisappear()</strong> nor <strong>viewDidDisappear()</strong> was called after the app quit in iOS simulator. I'm using a single view template, not navigation controller in similar questions.</p>
  
  <p>Here is the source code:</p>
  
  <pre><code>#import "ViewController.h"
  
  @interface ViewController ()
  
  @end
  
  @implementation ViewController
  
  - (void)viewDidLoad {
      [super viewDidLoad];
      NSLog(@"viewDidLoad() called");
      // Do any additional setup after loading the view, typically from a nib.
  
      NSString *filePath = [self dataFilePath];
      if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
          NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
          for (int i = 0; i &lt; 4; i++) {
              UITextField *theField = self.lineFields[i];
              theField.text = array[i];
          }
      }
  
      UIApplication *app = [UIApplication sharedApplication];
      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(applicationWillResignActive:)
                                                   name:UIApplicationWillResignActiveNotification
                                                 object:app];
  
  }
  
  - (void)viewWillDisappear:(BOOL)animated {
      NSLog(@"viewWillDisappear() called");
      [super viewWillDisappear:animated];
      [[NSNotificationCenter defaultCenter] removeObserver:self];
  }
  
  - (void)didReceiveMemoryWarning {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  }
  
  - (NSString *)dataFilePath {
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentDirectory = paths[0];
      return [documentDirectory stringByAppendingPathComponent:@"data.plist"];
  }
  
  - (void)applicationWillResignActive:(NSNotification *)notification {
      NSString *filePath = [self dataFilePath];
      NSArray *array = [self.lineFields valueForKey:@"text"];
      [array writeToFile:filePath atomically:YES];
  }
  
  @end
  </code></pre>