iOS Development

swift – Flutter & OneSignal: Updating UI with background push notifications (iOS)

Spread the love

I’ve a flutter app that has push notifications performance. For managing push notifications I am utilizing one sign package deal. Thus far it really works fairly effectively, however I discovered myself strugling with dealing with notifications after I recieve them within the background. I would like it as a result of I need to replace record of notifications that consumer see within the app every time new notification acquired. One sign does not have it in-built and I attempted so as to add it myself.

I’ve tried to regulate swift code for this, and due to the dearth of expertise of working with swift it is a bit difficult for me. I’ve tried so as to add this operate – software(_:didReceiveRemoteNotification:fetchCompletionHandler:) to the AppDelegate as a result of in keeping with the apple documentation it needs to be triggered when notification is acquired both in foreground or background mode. I’ve tried to debug it and put some break factors and prints however it was by no means triggered. I additionally tried to make use of NotificationServiceExtension to make it work, and it appears like didReceive(_:withContentHandler:) operate right here is trigerred because it ought to, however the issue is that as a result of it is outdoors of the AppDelegate I am unsure how I can go infromation about notification from the swift to flutter as a result of I do not know methods to get binaryMessenger right here

So I would prefer to make clear a couple of issues:

  1. Is it potential to one way or the other ship knowledge from NotificationServiceExtension to AppDelegate? As a result of I’ve seen some articles and I am unsure about it as a result of it appears they’re operating in several containers
  2. Possibly it could be potential to ship knowledge immediately from NotificationServiceExtension on to the flutter aspect?
  3. Is there different approaches how I may catch notifications and ship them on to the flutter aspect?

Beneath the swift code that I’ve used:

import UIKit
import Flutter

@objc class AppDelegate: FlutterAppDelegate {
    var flutterChannel: FlutterMethodChannel!
    override func software(
        _ software: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        let binaryMessenger = (window.rootViewController as! FlutterViewController).binaryMessenger
        flutterChannel = FlutterMethodChannel(title: "my.notification", binaryMessenger: binaryMessenger)

        GeneratedPluginRegistrant.register(with: self)
        return, didFinishLaunchingWithOptions: launchOptions)
    override func software(_ software: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        self.flutterChannel.invokeMethod("getNotification", arguments: "Notification from push")

One thought on “swift – Flutter & OneSignal: Updating UI with background push notifications (iOS)

  1. certainly like your website but you need to take a look at the spelling on quite a few of your posts Many of them are rife with spelling problems and I find it very troublesome to inform the reality nevertheless I will definitely come back again

Leave a Reply

Your email address will not be published. Required fields are marked *