HomeiOS Developmentswift - Flutter & OneSignal: Updating UI with background push notifications (iOS)

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


I’ve a flutter app that has push notifications performance. For managing push notifications I am utilizing one sign bundle. Thus far it really works fairly nicely, however I discovered myself strugling with dealing with notifications once I recieve them within the background. I would like it as a result of I need to replace checklist of notifications that consumer see within the app every time new notification obtained. 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’s kind of difficult for me. I’ve tried so as to add this perform – utility(_:didReceiveRemoteNotification:fetchCompletionHandler:) to the AppDelegate as a result of in line with the apple documentation it must be triggered when notification is obtained both in foreground or background mode. I’ve tried to debug it and put some break factors and prints nevertheless it was by no means triggered. I additionally tried to make use of NotificationServiceExtension to make it work, and it appears like didReceive(_:withContentHandler:) perform right here is trigerred because it ought to, however the issue is that as a result of it is exterior of the AppDelegate I am unsure how I can cross infromation about notification from the swift to flutter as a result of I do not know how one can get binaryMessenger right here

So I might wish to make clear a couple of issues:

  1. Is it doable 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 numerous containers
  2. Possibly it will be doable to ship knowledge straight from NotificationServiceExtension on to the flutter facet?
  3. Is there different approaches how I may catch notifications and ship them on to the flutter facet?

Under the swift code that I’ve used:

import UIKit
import Flutter

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

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

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments