title: iOS push notifications and AppDelegate methods behaviour
body: <p>I did some research on lots of stackoverflow issues and websites in trying to figure out how do the iOS push notifications influence <code>AppDelegate</code> lifecycle methods and when is which method (not) getting triggered. Main focus of the research was on "standard" iOS push notifications (with <code>alert</code> field) and silent ones (with just <code>content-available</code> set to <code>1</code>) and on AppDelegate's <code>application:didReceiveRemoteNotification</code> and <code>application:didFinishLaunchingWithOptions</code> methods.</p>
  
  <p>I don't want to ask lots of questions for different scenarios, but would rather try to write down the statements about different test cases I tried and ask you after that: </p>
  
  <p><code>Is there any statement that is wrong and if yes, which one and why?</code></p>
  
  <hr>
  
  <h3>Scenario 1: App has been used and put to background by tapping the home button.</h3>
  
  <ol>
  <li><p>If standard push notification is sent, in the moment of push notification arrival, none of the methods gets triggered, app remains inactive in background. Once push notification has been tapped and app got opened because of it, <code>application:didReceiveRemoteNotification</code> method got called and <code>application:didFinishLaunchingWithOptions</code> doesn't get called. I tested this scenario right after putting the app to background and also after an app being in background for more than an hour - same behaviour. I guess that if for some reason iOS decided to kill my app while being in background, this test case becomes like Scenario 2, statement 1 from below, right?</p></li>
  <li><p>If silent push notification is sent, in the moment of the push notification arrival, <code>application:didReceiveRemoteNotification</code> method got called and <code>application:didFinishLaunchingWithOptions</code> doesn't get called.</p></li>
  </ol>
  
  <hr>
  
  <h3>Scenario 2: App has been used and killed by swiping it out of the list of running apps.</h3>
  
  <ol>
  <li><p>If standard push notification is sent, in the moment of push notification arrival, none of the methods get triggered, app remains killed. Once push notification has been tapped and app got opened because of it, <code>application:didReceiveRemoteNotification</code> method got called and <code>application:didFinishLaunchingWithOptions</code> doesn't get called.</p></li>
  <li><p>If silent push notification is sent, none of the methods gets triggered since silent push notifications fail to be sent to the app that got killed. After opening an app after notification is sent, <code>application:didFinishLaunchingWithOptions</code> gets called as part of the normal flow and without any push notification information. <code>application:didReceiveRemoteNotification</code> doesn't get called.</p></li>
  </ol>
  
  <hr>
  
  <p>If you can maybe think of some other real life scenarios that I maybe forgot to mention, I would be really grateful to find out about them and what happens in those cases.</p>
  
  <p>Cheers</p>
  
  <hr>
  
  <h3>Update #1</h3>
  
  <p>Thanks to Sandeep Bhandari for the update and additional scenarios. I forgot to mention in my original question that I was exploring scenarios in which application is arriving to the app that is currently <code>not</code> in the foreground for whatever reason.</p>
  
  <p>Adding Sandeep's scenarios to the list:</p>
  
  <hr>
  
  <h3>Scenario 3: App is being used and push notification arrives.</h3>
  
  <ol>
  <li><p>If standard push notification is sent <code>application:didReceiveRemoteNotification</code> method will get called. <code>application:didFinishLaunchingWithOptions</code> will not get called.</p></li>
  <li><p>If silent push notification is sent <code>application:didReceiveRemoteNotification</code> method will get called. <code>application:didFinishLaunchingWithOptions</code> will not get called.</p></li>
  </ol>
  
  <hr>
  
  <h3>Scenario 4: App being alive in background.</h3>
  
  <ol>
  <li><p>If standard push notification is sent <code>application:didReceiveRemoteNotification</code> method will get called. <code>application:didFinishLaunchingWithOptions</code> will not get called.</p></li>
  <li><p>If silent push notification is sent <code>application:didReceiveRemoteNotification</code> method will get called. <code>application:didFinishLaunchingWithOptions</code> will not get called.</p></li>
  </ol>
  
  <hr>