FCM Background handling in Flutter - iOS - flutter

What I want to achieve
I'm implementing FCM in flutter for iOS in such a way that in every state (foreground, background and terminated) when the notification is received, we need to show an alert with sound on the screen for some time (Say 2 mnts).
What is clear
Implementation is clear when the app is in foreground which can easily be done using onMessage callback.
Where is the issue
The confusion is with background and terminated part:
How to detect in the background that notification is received (I
know on Resume is called when we click on the notification in the
notification try). But we need to show alert on notification arrival
not on Clicking the notification.
How to detect when the app is terminated(I know onLaunch is called
when we click on the notification in the notification tray) But we
need to show alert on notification arrival not on Clicking the
notification.
Is it possible to show any system alert when the app is not running
like when notification is received while app is terminated and we
show a customized alert like Alarm alert on the screen.
There is onBackgroundMessage call back but I don't know if it works
for iOS (as documentation is more focused on Android settings in
onBackgroundMessage call back part).

Related

Notification Timer should continue even if app is close without another notification

In my app there is condition where a notification is generated at button click and showing with Countdown it is working fine if app is open. With the help of background service notification timer also working fine even if app is close but I have to show extra notification for Background service in Android devices.
I am using flutter_local_notifications: ^9.2.0 and flutter_background_service: ^2.3.9
Is there any way to achieve my goal without background service and without extra notification.

How do i set up foreground notifications in flutter app?

I am sending notifications from firebase.
Background notification works fine but I can't find something that worked in foreground for me.
I want to display the notification when the app is open same as when the app is in background.
with system notification sound and same banner display at the top of screen.
You can control this on iOS
FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(badge: true, alert: true, sound: true);
package:firebase_messaging/firebase_messaging.dart
Sets the presentation options for Apple notifications when received in
the foreground.
By default, on Apple devices notification messages are only shown when
the application is in the background or terminated. Calling this
method updates these options to allow customizing notification
presentation behaviour whilst the application is in the foreground.
Important: The requested permissions and those set by the user take
priority over these settings.
[alert] Causes a notification message to display in the foreground,
overlaying the current application (heads up mode). [badge] The
application badge count will be updated if the application is in the
foreground. [sound] The device will trigger a sound if the application
is in the foreground. If all arguments are false or are omitted, a
notification will not be displayed in the foreground, however you will
still receive events relating to the notification.

Local User Notification action tapped on watch not delivered to iOS app

I have an iOS 10 app and watchOS 3 extension that uses iOS 10 User Notifications Framework. The local notification is scheduled from the iOS app, and is shown on the watch when the iPhone is locked, and shown on the iOS app on the lock screen if I raise my iPhone, and don't respond to the watch. The iOS notification have three background action buttons.
If I respond to the notification on my iPhone, the userNotificationCenter(_:didReceive:withCompletionHandler:) UNUserNotificationCenter delegate method is called correctly. But if I instead tap on one of the action buttons on my watch, the function is not called.
According to Apple's App Programming Guide for watchOS, under the section Responding to Selected Actions:
For background actions, the handling of actions depends on where the notification was scheduled:For local notifications scheduled on iPhone, background actions are handled by your iOS app regardless of which device displayed the notification.
This is not happening, and I don't know why. Have anyone got this working from the watchOS?
It looks like I didn't put the correct options in the UNNotificationAction. The options should be an empty array, instead of the .foreground I had mistakenly put there.
So for e.g. the Just Practice button, the correct action for it to be background is:
let justPracticeAction = UNNotificationAction(identifier: "justPractice", title: "Just Practice", options: [])

iOS add notification to the lockscreen that will not disappear

is it possible to add a notification to the lockscreen that will not disappear?
or (my second choice)
Is it possible to add a notification to the lockscreen, which will be thre until the iPhone is unlocked the next time?
For example:
iPhone is unlocked
message incoming
lock iPhone
message is in lockscreen
unlock iPhone
message is not longer in lockscreen
Edit:
My goal is to have a notification on the lockscreen every time.
No, neither is possible. If your app is in foreground, it gets delivered to your app directly and is not displayed. If the screen is locked or you app is in background, the notification is shown.
in ios5 there is a new feature in notification that notifications are automatically shown in the lockscreen if the user select the option from the setting but your app cannot receive any notification if your app in foreground.

Is it possible to receive push notifications in background mode

Is it possible to receive all push notifications that app recieved in background mode.
I mean that when app runned and then app went to background mode and then app recieve push notifications(in background mode) and user does not press view button on alert message (this button run app) and after some minutes user launch app, in this point I want get all push notifications that my app recieve in background mode.
Yes, applications can and do receive Push Notifications whether they are backgrounded or not even active. In your applicationDidEnterBackground: method you can check to see if your app has received a notification, then handle it from there.