title: Silent pushes not delivered to the app on iOS 11
body: <p>I noticed that on iOS 11 beta 2, the silent notifications are not delivered to the <code>application:didReceiveRemoteNotification:fetchCompletionHandler</code> regardless the state of the app (background / foreground).</p>
  
  <p>I implemented the <code>UIApplicationDelegete</code> method <code>application:didReceiveRemoteNotification:fetchCompletionHandler</code> and I send the following silent push</p>
  
  <pre><code>{  
    "aps": {  
      "content-available": 1  
    },  
    "mydata": {  
      "foo": "bar"  
    }  
  } 
  </code></pre>
  
  <p>but the delegate method is not called on iOS 11. </p>
  
  <p>It works fine on other versions of iOS and the documentation section <a href="https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW8" rel="noreferrer">Configuring a Silent Notification</a> does not mention that anything else should be done.</p>
  
  <p>Is this a bug in iOS 11 or did I miss something new in iOS 11? </p>
  
  <p>Please note that I'm not talking about or using the <code>UserNotification</code> framework which should not be needed for sending silent pushes.</p>
  
  <p>Here is a <a href="https://www.dropbox.com/s/qdk3dh9irpsmbgi/PushBug11.zip?dl=0" rel="noreferrer">sample project</a> that illustrates the issue (you'll have to set your own bundle id)</p>
  
  <p>When you lunch the sample project and send a above payload to the app, you can use the macOS console to see that the push is correctly delivered to the device but not to the app.</p>
  
  <h1>UPDATE 10.08</h1>
  
  <p>It appears that the behaviour is random. Sometimes after restarting the device, the payload is delivered correctly but it stops working after a while.</p>
  
  <p>As you can see on the following screenshot, the push marked as 1 is delievered only to the device and the push 2 (after device restart) is also delivered to the app.</p>
  
  <p><a href="https://i.stack.imgur.com/d5Avv.png" rel="noreferrer"><img src="https://i.stack.imgur.com/d5Avv.png" alt="enter image description here"></a></p>
  
  <h1>UPDATE 14.08 - iOS 11 Beta 6</h1>
  
  <p>Still the same behaviour. Another thing that is supposed to work but does not is the following. When the application's scheme is set to "Wait for executable to be launched", a silent push is supposed to wake up the app and start it in background. </p>
  
  <p><a href="https://i.stack.imgur.com/S5DbS.png" rel="noreferrer"><img src="https://i.stack.imgur.com/S5DbS.png" alt="enter image description here"></a></p>
  
  <h1>UPDATE 21.08 - iOS 11 Beta 7</h1>
  
  <p>Still the same behaviour and not updates from Apple in the bug report.</p>
  
  <h1>UPDATE 29.08 - iOS 11 Beta 8</h1>
  
  <p>Still the same problem. The steps to reproduce I use now are the following:</p>
  
  <ul>
  <li>In the Xcode project scheme, select "Wait for executable to be launched"</li>
  <li>Add a breakpoint in the <code>didReceiveRemoteNotification: fetchCompletionHandler</code></li>
  <li>Start the app on device</li>
  <li>Send the above silent push</li>
  </ul>
  
  <p><strong>Expected</strong>: The app is brought from suspended state to background and the <code>didReceiveRemoteNotification: fetchCompletionHandler</code> is called</p>
  
  <p><strong>Actual</strong>: nothing happens </p>
  
  <h1>UPDATE 06.09 - iOS 11 Beta 10</h1>
  
  <p>I'm still having the same buggy behaviour. The ticket from Apple was updated with the following answer:</p>
  
  <blockquote>
    <p>Apple Developer Relations September 6 2017, 10:42 PM Engineering has
    provided the following feedback regarding this issue: </p>
    
    <p>We were able to get the sample app running and test the behavior. We
    didn’t see any issues when we tested this as described. </p>
    
    <p>Pushes aren't guaranteed to arrive to the app when it is running in
    the background, and the logs here indicate we don't believe the app is
    being used enough to launch it. </p>
    
    <p>We do see us delivering pushes from time to time when conditions are
    good. </p>
    
    <p>We believe this is behaving correctly.</p>
  </blockquote>
  
  <h1>Update 11.09</h1>
  
  <p>My Apple bug report was closed and marked as duplicate of <code>33278611</code> which remains open</p>
  
  <h1>UPDATE 13.09 - iOS 11 GM</h1>
  
  <p>Thanks to kam800's comments (see below) I did more testing and came up with those observations:</p>
  
  <p>There seem to be a new daemon in iOS 11 <code>dasd   DuetActivitySchedulerDaemon</code> that either completely discards the data push or delays the data push delivery:</p>
  
  <h3>Delivery postponed</h3>
  
  <p><strong>Console Logs</strong></p>
  
  <pre><code>default 13:11:47.177547 +0200   dasd    DuetActivitySchedulerDaemon CANCELED: com.apple.pushLaunch.net.tequilaapps.daylight:C03A65 &lt;private&gt;!   lifecycle   com.apple.duetactivityscheduler
  default 13:11:47.178186 +0200   dasd    DuetActivitySchedulerDaemon Removing a launch request for application &lt;private&gt; by activity &lt;private&gt;   default com.apple.duetactivityscheduler
  default 12:49:04.426256 +0200   dasd    DuetActivitySchedulerDaemon Advancing start date for &lt;private&gt; by 6.5 minutes to Wed Sep 13 12:55:31 2017   default com.apple.duetactivityscheduler
  default 13:21:40.593012 +0200   dasd    DuetActivitySchedulerDaemon Activity &lt;private&gt;: Optimal Score 0.6144 at &lt;private&gt; (Valid Until: &lt;private&gt;)  scoring com.apple.duetactivityscheduler
  default 13:21:40.594528 +0200   dasd    DuetActivitySchedulerDaemon Setting timer (isWaking=1, activityRequiresWaking=0) between &lt;private&gt; and &lt;private&gt; for &lt;private&gt;  default com.apple.duetactivityscheduler
  </code></pre>
  
  <p><strong>Postponed delivery issues</strong></p>
  
  <ul>
  <li>When the data push delivery is postponed and the app is launched, the data push is delivered only when the delivery date is reached which can be <em>several minutes</em> in the future. This defeats completely the purpose of using data pushes to keep the new app's content ready for the next launch. I quote here once again Apple's documentation: </li>
  </ul>
  
  <blockquote>
    <p>"Silent notifications improve the user experience by helping you keep
    your app up-to-date, even when it is not running."</p>
  </blockquote>
  
  <ul>
  <li>When <strong>two</strong> data pushes are sent to a suspended app they are postponed by iOS 11 instead of waking up the app directly. When delivery time is reached, <em>only the last</em> data push is delivered! The previous pushes are lost and not delivered via the delegate method resulting in a data loss.</li>
  </ul>
  
  <h3>Delivery cancelled</h3>
  
  <p><strong>Console Logs</strong></p>
  
  <pre><code>default 13:35:05.347078 +0200   dasd    DuetActivitySchedulerDaemon com.apple.pushLaunch.net.tequilaapps.daylight:C03A65:[
      {name: ApplicationPolicy, policyWeight: 50.000, response: {Decision: Must Not Proceed, Score: 0.00}}
   ], FinalDecision: Must Not Proceed}    scoring com.apple.duetactivityscheduler
  </code></pre>
  
  <p><strong>Cancelled delivery issues</strong></p>
  
  <p>Well in this case, the data push is completely lost and never delivered on iOS 11 while it was delivered correctly on iOS 10.</p>
  
  <h1>UPDATE 19.09 - iOS 11 GM</h1>
  
  <p>I also noticed that when the application is in the foreground and the notification is not delivered to the app, I see the following logs in the console:</p>
  
  <pre><code>default 08:28:49.354824 +0200   apsd    apsd    &lt;private&gt;: Received message for enabled topic '&lt;private&gt;' onInterface: NonCellular with payload '&lt;private&gt;' with priority 10 for device token: NO   courier-oversized   com.apple.apsd
  
  fault   08:33:18.128209 +0200   dasd    Foundation  &lt;NSXPCConnection: 0x151eee460&gt; connection from pid 55: Exception caught during decoding of received message, dropping incoming message.
  Exception: Exception while decoding argument 0 (#2 of invocation):
  Exception: value for key 'NS.objects' was of unexpected class 'NSNull'. Allowed classes are '{(
      NSArray,
      NSData,
      NSString,
      NSNumber,
      NSDictionary,
      NSUUID,
      _DASActivity,
      NSSet,
      _DASFileProtection,
      NSDate,
      NWParameters,
      NWEndpoint
  )}'.    general com.apple.foundation.xpc
  </code></pre>