I have a flutter app that uses flask as backend and when ever some data changes in the backend, I want to send an Alert Dialog to user. Although I know how to use Alert Box, I'm confused where the code for it should be placed as I'm using 3 screens and navigating then via PageView.
My use case is that I have a PIR sensor equipped onto a raspberry pi and when ever motion is detected, motion_status value turns to true and sends to flutter app via flask app.
I'm confused about where i need to place the Alert Dialog widget so that when ever movement happens, no matter what screen i'm in i should get alert box .
So when an update happen in the backend, you have couple different ways to get the app notified about the change just happened,
1- first you create a stream in the flutter app calling the server to check if any change happened, that stream reoccurs every few minutes or seconds, but that's not a good solution because there will be a lot of calls to the server and the info won't be instant.
2- use a web socket system
Best solution
3- use FCM Firebase cloud messaging system, whenever a change happened in the backend you write a code that calls Firebase account associated with your flutter app and your Firebase account will send a notification with data load to your app, when your app receives that real time notification you can then show to the user the alert dialog
Related
I am new to the world of mobile development.
I'm currently using flutter_foreground_task to create the service and push the updates to UI.
The problem I'm having is trying to send data to the service from the UI.
I have tried with MethodChannel EventChannel and I have not been able to achieve it, in the documentation that I have read nothing is mentioned about it.
Example.
By pressing a button I need to send data to the service to notify said action and send data through a websokect.
Example.
By pressing a button I need to send data to the service to notify said action and send data through a websokect.
By chance you could help me by guiding me what I should implement to make that communication.
I'm using with success the flutter local notification plugin. Now I'm struggling for create a page with all notifications.
Is there a way to collect all incoming local notifications of my app (even if dismissed and/or not clicked) in a list (the classic notification page like FB etc.)
I only notice that I can track the tapped notification but not only the arrival notification.
Thanks!
This unfortunately is not possible, because notifications are not stored anywhere. They exist in memory on the device, until the user dismisses them, or they are replaced with a message of a similar ID, or the OS just removes them altogether.
Your best bet, is to generate a table on your mobile backend, that will store these notifications (the same ones that will be broadcasted to the users notification center), then get the app to read directly from this table, and store it on a local SQLite database.
These notifications that are broadcasted, will need to be sent from the backend itself, with the exact same content, as that being stored on the table I mentioned. This will ensure data integrity between the notification center, and that of the app.
[EDIT]
Please make sure that you use FCM (Firebase Cloud Messaging) for mobile push notifications. These are completely free, as per the documentation:
https://firebase.google.com/docs/cloud-messaging
For Tutorials, please look at these:
https://medium.com/#jun.chenying/flutter-tutorial-part3-push-notification-with-firebase-cloud-messaging-fcm-2fbdd84d3a5e
https://www.freecodecamp.org/news/how-to-add-push-notifications-to-flutter-app/
My app is receiving APNs sent from server to Apple backend. Naturally a user may not open the app once a notification arrives to user's device. In meantime my server may push more notifications. They all contain some user data that is important when a notification is processed. So how to deal with it? iOS won't bundle and give me a batch, will it?
Here are ways how I am going to tackle it, none of which is simple.
Server keeps track of not seen data and upon arriving a new request always sends a batch of all new notifications, reflecting the count as badge count.
Client is opened by taping on notification popup. In this case it has all needed data in didReceiveRemoteNotification.
OR
Client ignores notification popup and opens app (possibly later) by tapping on app icon. In this case didReceiveRemoteNotification is not called and thus app has to fetch all needed data from server.
OR
Server never sends any user data and client always checks for new stuff every time it starts or fetches data in didReceiveRemoteNotification.
Anything else? Something simpler I am missing?
Number 4 is the right approach. There is no guarantee that any of your app code will run when an APN is received, except on iOS7. So when your app starts, it has to check with your servers for any new information that it should display.
It's simplest to code this to alway ask your servers for the latest information to display, rather than rely on the information in the APN. Use the information in the APN only to determine which new information to navigate to, so that the app displays whatever the user tapped on.
This has changed with iOS7, where you can use the remote-notification background mode to be launched whenever a push message arrives. See https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didReceiveRemoteNotification:fetchCompletionHandler:
I have implemented all recommended methods in AppDelegate to get working Remote Notifications service.
I can accept them while running, while launching and while turned off.
But there is an issue, since I can't work with many received notifications while in background. I can work only with latest notification.
What is recommended manual to do that? How can I got all notifications received while in background? Is it only solvable via manual call to my service provider (sender of apns data)?
With all the projects I've worked on there hasn't been a way to locally store this information if the push notification is dismissed. In all those cases we used a small file on the server that the app would connect to and pull when it became active again. There was also some place in the app where the user could see all their notifications which, again, were stored on the server for quick retrieval.
With the way I understand push notifications to be setup, if the notification is dismissed the system discards it. It'll perform anything it's supposed to do (such as update the badge number and play the correct sound) but any additional information specific to that notification is lost.
Not sure if this helps, but if you just want to know how many notifications you have missed while you were in background. You can create a variable which contains notification number and store this in the app every time you handle notification. When you come out of background and receive a new notification you can subtract the new number with the stored number to find out the number of missed notifications. I don't think there is a way where iOS can give you complete data associated with all the notification device have received while the app was in background.
The best solution is to keep a list of sent notifications with all relevant data on your server, so the app can access that data when it launches. Sending multiple notifications with data that is not stored on the server can be risky, because the application only receives the notification when the user opens the app from that notification, so if they tap on one notification, the app will only every receive that one.
If you have them all in a list on your server, the app can simply go and pull that list down, and process it, making sure no data is lost.
i'm working on a football application. the application connects to a webservice and gets the required data via soap request whenever a tab is opened. one of the tab shows live matches of the current day. when the live tab is opened, it refreshes the view by a timer and shows the status updates (goal scored, half time or full time). what i need to do is getting the status updates when the app is closed. the user will select max 2 competitions from settings of the app. then the status updates about these 2 competitions needed to be alerted. can i use push notification service to send soap requests and make alerts according to the response? or does it only allow getting response? or is there anyway that i can do it?
thanx in advance.
I'm not entirely clear what you are asking. The part where you write:
can i use push notification service to send soap
requests and make alerts according to the response?
or does it only allow getting response?
isn't really clear to me. What response are you talking about?
In any case.. push notification is what is says. It pushes a notification to the iPhone.
It does not:
activate your application in the background
allow for any action of your application without the user opening said application first
allow any kind of data to be gather from the phone
If you want the user's phone to talk to your server, the user will need to open your application. If that's what you're asking.