iOS Forground Push

Hi,

my Flutter App should received and show Push notifications even if my App is in Foreground and active.

If i register my Device with:
await Backendless.messaging.registerDevice( [‘default’] , null, _onPushMessageReceived ));

my _onPushMessageReceived get called and I can see the Push. So in general my Push chain works but I can’t configure my App that I get a native Forground Push.

My iOS App Delegate:

@UIApplicationMain

@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) → Bool {
GeneratedPluginRegistrant.register(with: self)

    if #available(iOS 10.0, *) {
        let center = UNUserNotificationCenter.current()
        center.delegate = self
        center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
            DispatchQueue.main.async {
                UIApplication.shared.registerForRemoteNotifications()
            }
        }
    } else {
        let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        UIApplication.shared.registerUserNotificationSettings(settings)
        DispatchQueue.main.async {
            UIApplication.shared.registerForRemoteNotifications()
        }
    }
    
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self
    }
    
     return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

override func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    completionHandler([.banner, .badge, .sound])
}

}

So, is there a way to send the Push i received with _onPushMessageReceived back to iOS or a Config that my App never got the Push so that iOS handle everything like a Push if my App is in Background?

Regards,
Stephan

Hello, @Stephan_Tomforde.

In my project this is looks like this:

                let center = UNUserNotificationCenter.current()
                center.delegate = self
                center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
                    if let error = error {
                        print(":red_circle: APNS error: \(error.localizedDescription)")
                        result(false)
                    }
                    else {
                        DispatchQueue.main.async {
                            UIApplication.shared.registerForRemoteNotifications()
                        result(true)
                    }
                }
    public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        print("userNotificationCenter called");

          completionHandler([.banner, .badge, .sound, .list])
    }

I haven’t seen principal differences exclude that my method not overridden, try to set just public func instead of override, also my compilationhandler look like this:
completionHandler([.banner, .badge, .sound, .list]).

Additionally, make sure that this code has been called:

        let center = UNUserNotificationCenter.current()
        center.delegate = self
        center.requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
            DispatchQueue.main.async {
                UIApplication.shared.registerForRemoteNotifications()
            }
        }

Best Regards, Nikita.