admin管理员组文章数量:1410688
I'm trying to implement background push notifications in my Flutter app. The goal is to trigger a process in the background when a push notification arrives, and as a proof of concept, I just want to log something to confirm the device is receiving the notification. The device receives alert push notifications normally, but I don't see any logs or responses when a background push notification (a type of push notification with "content-available": 1) arrives, whether the app is in the foreground, background, or terminated.
Here’s what I have so far:
- In AppDelegate.swift:
override func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
// Log to confirm that background notification was received
NSLog("Background push notification received.")
// Attempt to invoke Flutter method to handle the notification
do {
let someData = "Notification data received" // Example data you want to pass
self.channel?.invokeMethod("backgroundNotificationArrived", arguments: someData) { (result) in
let resultDescription = String(describing: result)
completionHandler(.newData) // Indicate that new data was received
NSLog("Flutter method backgroundNotificationArrived invoked, response: \(resultDescription)")
}
} catch {
// Handle any errors and log the failure
NSLog("Error invoking Flutter method or serializing userInfo: \(error.localizedDescription)")
completionHandler(.failed) // Indicate failure in processing
}
}
- In Info.plist:
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>location</string>
<string>processing</string>
<string>remote-notification</string>
</array>
- Sending the Body from Apple Developer Push Notifications Platform:
{
"aps": {
"content-available": 1
},
"custom-data": "true"
}
- Flutter Code (simplified for context): I’m using Flutter with Swift code to handle the background notifications. The method backgroundNotificationArrived is supposed to be triggered when the background push notification arrives. However, the notification doesn’t seem to be triggering or logging anything.
Questions:
- Is there anything I'm missing in the setup to ensure the app wakes up to process background push notifications when the app is in the background or terminated?
- What debugging steps should I take to verify that the background fetch is being triggered, especially when the app is in the background or terminated?
I was following this article to send the background push notification:
Thank you in advance for any suggestions or insight!
本文标签:
版权声明:本文标题:ios - Flutter Background Push Notification: Not Receiving Notification or Logging in AppDelegate.swift - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744809384a2626343.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论