UNNotificationServiceExtension fails to update notifications occasionally
<p>I have a <code>UNNotificationServiceExtension</code> written in Swift. All it does:</p>

<ul>
<li>Set notification title</li>
<li>Set notification body</li>
<li>Load image &amp; call <code>contentHandler ()</code></li>
</ul>

<p>Here's a shorted version of what am I doing:</p>

<pre><code>override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -&gt; Void) {
    self.contentHandler = contentHandler
    self.bestAttemptContent = request.content.mutableCopy() as? UNMutableNotificationContent

    bestAttemptContent!.title = GetNotificationTitle(userInfo)
    bestAttemptContent!.body = GetNotificationBody(userInfo)

    if let imageUrl = &lt;get image url&gt; {
        let imageLoaderTask = URLSession.shared.dataTask(with: URL.init(string: imageUrl)!) { (newsImageData, newsImageUrl, newsImageError) -&gt; Void in
            if newsImageError == nil &amp;&amp; newsImageData != nil {
                let documentDirectory = self.GetDocumentDirectory()
                if documentDirectory != nil {
                    let newsFileURL = documentDirectory?.appendingPathComponent("news_image").appendingPathExtension("png")
                    do {
                        try newsImageData?.write(to: newsFileURL!)
                        let attachment = try UNNotificationAttachment(identifier: "newsImage",
                                                                      url: newsFileURL!,
                                                                      options: nil)
                        self.bestAttemptContent?.attachments = [ attachment, ]
                        self.contentHandler!(self.bestAttemptContent!)
                        return
                    } catch {}
                }
            }
            self.contentHandler!(self.bestAttemptContent!)
        }
        imageLoaderTask.resume()
    } else {
        self.contentHandler!(self.bestAttemptContent!)
    }
}
</code></pre>

<p>In <strong>95% cases - it works just fine</strong>. However, <strong>occasionally</strong> notification arrives without any changes (i.e. title, body remained the same, no image has been attached).</p>

<p>I know that:</p>

<ul>
<li>It's not timeout: <code>serviceExtensionTimeWillExpire</code> is not called</li>
<li>It doesn't look like <code>UNNotificationServiceExtension</code> crashes: I've added plenty of <code>NSLog()</code> calls to check Device Logs - <strong><code>self.contentHandler!(self.bestAttemptContent!)</code> fires</strong></li>
<li>It happens more often on my iPhone rather than on iPad</li>
<li>I haven't found any single clue in Device Logs regarding the issue</li>
</ul>

<p>Does anyone faced this issue? Any workarounds? Thoughts?</p>