Skip to content

Instantly share code, notes, and snippets.

@knaeckeKami
Created February 6, 2025 20:57
Show Gist options
  • Save knaeckeKami/4bf416ac0a1c6659e9c3c161bfffca45 to your computer and use it in GitHub Desktop.
Save knaeckeKami/4bf416ac0a1c6659e9c3c161bfffca45 to your computer and use it in GitHub Desktop.
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate, OrientationDelegate {
var lastNotificationData: [AnyHashable: Any]?
var isChannelInitialized = false
...
override func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
// Send the notification data to Flutter
if(!isChannelInitialized) {
// If the channel isn't initialized yet, save the notification data
self.lastNotificationData = userInfo
} else if let controller = (UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController as? FlutterViewController {
let channel = FlutterMethodChannel(name: "com.helloinside.glucose/notification", binaryMessenger: controller.binaryMessenger)
channel.invokeMethod("onNotificationTap", arguments: userInfo) { result in
print("Method call result: \(result)")
}
} else {
// If we can't get the FlutterViewController, save the notification data
self.lastNotificationData = userInfo
}
completionHandler()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment