I have a UNNotificationServiceExtension that works fine i would say 95% of the time. However, ocassionally the notification arrives without the content that gets downlaoded and attached to the notification. I am also using a content extension. I've checked the logs and it has nothing to do with the code in the service extension, it's almost as if the system forgets to fire of the service extension in the first place. I've noticed this when one of the un-modified notifications came through and the service extension wasn't a running process on the phone at the time. Is this an iOS bug?
UNNotificationServiceExtension fails to update notifications occasionally
We're experiencing that same problem.
After a lot of tries to reproduce this bug in debug mode with a lot of print statements,
my only conclusion is that system sometimes doesn't call `contentHandler` so notification is displayed not-modified.
Here's some code I used for debugging:
import UserNotifications
import UIKit
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest,
withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
print("didReceive called")
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
let notification = WANotification(userInfo: bestAttemptContent.userInfo)
print("notification created")
if let shortBody = notification.payload.bodyShort {
bestAttemptContent.body = shortBody /
print("body set")
} else {
print("no short body")
}
if let icon = notification.iconAttachment {
bestAttemptContent.attachments = [icon]
print("icon set")
} else {
print("no icon")
}
contentHandler(bestAttemptContent)
print("content handler called")
} else {
print("no best attempt content")
}
}
override func serviceExtensionTimeWillExpire() {
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
} else {
print("no content handler or best attempt content")
}
}
}
Now goes the interesting part: after reproducing this bug in debug mode, I sent 3 push notifications (with same payload), 2 were fine (had icon and modified body) but 1 still had unmodified content (no icon or body text changed), and what I got in console is this:
didReceive called
notification created
body set
icon set
content handler called
didReceive called
notification created
body set
icon set
content handler called
didReceive called
notification created
body set
icon set
content handler called
So, all of mine code was being called normally, except that one content handler wasn't been called internally by system.
I find this related to https://forums.developer.apple.com/message/197020#197020 because those steps (reinstall, reboot) helped me reproduce this bug while testing what's going on.
Any comment from Apple on this?
I have now reported this bug to Apple (#29400672).
Hey Tadija, I've reached out to Apple Techinical Support about this and they weren't able to figure out what was happening. I've sent over logs for both when notification was successful and when it failed and there was no significant difference or tell on why this was happening. This is really confusing. I will try those steps outliend in the link to see if that reproduces the issue for me as well.
Please keep me updated on the bug report. Maybe file it on openradar.me as well so everyone can see it.
Yes, I have the same issue, I spent a lot of time to debug because it appeared irregularly.
https://forums.developer.apple.com/message/197020#197020 help me for reproduce this issue a lot. I am very confused about this.
Now I can do is follow this forum, hope the answer from apple or somebody.
Please be sure to attach a sysdiagnose report to the bug. That contains detailed logging info that will help us see what happened.
Thanks,
--gc
I'm experiencing the same problem. What's the status of the bug now please?
We are experiencing the same problem. It can be reproduced by device rebooting. Our assumption is that it is some problem with internal attachment handling.
Please check our project we created for this issue:
https://github.com/appculture/RichNotificationAttachmentProblem
Hope someone or Apple can help!
Thanks!
Hi !
I'm experiencing this problem too ! I don't have to reboot my device, it's just that sometimes the extension seems to not being awaken by the OS...
Any news on a workaround or Apple fixing this issue ?
Thanks !
Anyone got hints to fix the problem?
Thanks
it could be crashing due to specific content or circumstances
it could be taking longer than 30 seconds (current limit as of iOS 14) and is ending without finishing the task
it could be using over 24MB (current limit as of iOS 14) memory and being terminated early
Thanks for the response, buddy. Much appreciated. However, i still need more information to track down this issue.
I said it does not trigger because when it triggers, i can see on the debug area.
second point is not valid since i removed all the processing and just changed the title to a static string but still the same problem.
How can i know that it is using more than 24 MB and that it was terminated early?
Thanks
@anthonysessa Hello, I have the same issue on iOS 17.2, Xcode 15.2. I've done all steps from your post here and from Stackoverflow one. Do you have any idea how to fix that?