Sunday, February 11, 2024
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 package deal. Thus far it really works fairly effectively, 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 listing of notifications that consumer see within the app every time new notification acquired. One sign does not have it inbuilt and I attempted so as to add it myself.

I’ve tried to regulate swift code for this, and due to the shortage 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 response to the apple documentation it must 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 nevertheless it was by no means triggered. I additionally tried to make use of NotificationServiceExtension to make it work, and it seems 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 move infromation about notification from the swift to flutter as a result of I do not know the way to get binaryMessenger right here

So I would wish to make clear a number of issues:

  1. Is it attainable to by some means ship information 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 will be attainable to ship information straight from NotificationServiceExtension on to the flutter aspect?
  3. Is there different approaches how I might catch notifications and ship them on to the flutter aspect?

Beneath the swift code that I’ve used:

import UIKit
import Flutter

@UIApplicationMain
@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 tremendous.software(software, didFinishLaunchingWithOptions: launchOptions)
    }
    
    override func software(_ software: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        self.flutterChannel.invokeMethod("getNotification", arguments: "Notification from push")
    }
}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments