9

I wonder how to push notifications to my Flutter app users in both Android and iOS devices Without using any external service like Firebase or OneSignal?

I want to implement a code in PHP which can send push real time notifications to all/spesific users in my Flutter app which works in both Android and iOS.

I found some solutions like flutter_local_notifications with workmanger which can fetch the API in the background only minimum 15 minuts. Workmanger is Not good solution because its work only during 15 min and it will consume the battery and internet.

I need an efficient solution to my flutter app for both Android & iOS devices, which can listen on real time to the coming messages from the server even when the app is closed.

How to fix that? thanks

mike
  • 708
  • 9
  • 18
  • 1
    I dont think that there is any working example in the past, here is another question with the same which is the same subject https://stackoverflow.com/questions/55557389/how-to-setup-push-notifications-with-flutter-without-firebase-and-with-own-custo You can either try to work with the work manager or have to use Firebase. – m123 Oct 18 '20 at 13:42
  • The problem is my backend is build in PHP and I cannot send information to external services because GDPR and Security. ThusI need another solution. Thanks for your comment. – mike Oct 18 '20 at 17:55
  • i have the same problem @M123 – lucky Jun 10 '21 at 15:01
  • do you have a solution for this ? @mike – lucky Jun 10 '21 at 15:02
  • 1
    @lucky No, I did not find any solution yet. – mike Jun 11 '21 at 16:56
  • @mike Why you think 15 minutes interval will consume a battery and the internet? It will make 96 requests everyday. – tylkonachwile Jul 21 '21 at 22:03
  • @mike, on iOS when the app is closed you can use a silent push notification (via Apple's Push Notification Server) to wake up the app. This gives the app 30seconds to perform necessary API calls etc in the background. As far as I'm aware, your iOS app will not be able to receive "real time" messages from your own server once put in the background. I'm unable to comment on Android apps. – ajmccall Feb 15 '22 at 11:56

2 Answers2

1

iOS

You will always need to integrate with Apple's Push Notification Server (APNS) if your app needs make API calls in the background. The reason is that once an app is put into the background, iOS will often put the app to sleep soon afterwards.

The correct approach to this is to use a silent push notification to wake up the app. When received, no message is shown on device but the app get's about 30 seconds in order to make API calls.

In your case, the app can make the API call and then schedule a local push notification to display your message.

Background updates via push notifications

Scheduling local push notifications

Android

It looks like WorkManager is your best bet. I don't see how it can affect battery.

FYI

You don't need to use Firebase or OneSignal for push notifications, silent or otherwise. They are simply 3rd party services that interact with the official Apple or Google Push Notification Servers.

ajmccall
  • 2,024
  • 23
  • 42
0

Unfortunately, I think this is not possible. Even OneSignal uses the Firebase API to deliver the notifications, as you can see here. For all other solutions, you will have to balance the update frequency with internet use and battery consumption.