We have been trying for the last two weeks to get a reliable solution to try and sync our app data with a server in the background. We have tried the Background fetch mechanism but due to the iOS restrictions on when it runs it is not a viable solution.
iOS does provide Remote Notifications (https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app?language=objc) that we would like to use as we can use the same mechanism on Android.
The issues is that when sending a type 2 notification CN1 only delivers the notification when the app is brought to the foreground by the user.
On Android I see there is a Build Hint for android.background_push_handling that allows the notifications to be sent to the app even if it is in the background.
Is there a similar build hint that we can use for iOS?
If not, is there a way then to override the application:didReceiveRemoteNotification:fetchCompletionHandler: method that fires when the Notification arrives so that we can forward it to our app?
You can use silent push notifications for that purpose. To send a silent push notification you just have to include "content-available" : 1" into the body of the notification. More info on that here: Apple docs-silent push notifications
You should bear in mind that this will only work when your app is in the background, it won't work when the app is killed. When the app is killed the only solution is standard push notifications, unless your app has VoIP functionality, in which case you are allowed to use PushKit framework (if you use it in an app without VoIP functionality, you won't get pass the AppStore).
Related
I'm trying to build a real time chat app.
I have integrated https://pub.dev/packages/flutter_local_notifications package for push notifications and this works.
I am NOT using Firebase, i am using my own custom backend that uses https://socket.io/ for real time chatting.
I want to receive a push notification when the user sends a chat message. Push notifications work when the app is in foreground or background. However when i terminate my app from the process (app is killed), the push notifications no longer work.
Is there a way to send push notifications without using Firebase so that i can receive notifications even when my app has been terminated from the process? I need this to work both for android and ios.
Basically, I don't recommend any solution for push notifications instead of firebase.
But if you have your reasons to use socket in this case I suggest you take a look into this package how it uses background service and tries to implement your own way to setup socket-based notification background service.
https://pub.dev/packages/background_locator
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
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.
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.
Customers can turn off push notifications at the app level. When that happens, we all know the the notification tray UI will not show up. But,
Does GCM/FCM (android) and APNS (iOS) continue to deliver notification to the customer's phone regardless ?
Specifically, on android & iOS, will I be able to execute some logic in the push event listener regardless of whether the user turned the push notifications on/off ?
In Android, when we disable push notifications, does the OS automatically unregister the app from GCM/FCM ?
Note:
I am NOT interested in background app refresh on iOS or background refresh through WorkManager on Android. I am NOT interested in iOS silent notifications or other kinds of Background Executions.
My question is specifically whether the code block is invoked (or not) when push notifications are turned off at app level (using the toggle).
I am not sure about the android, but in iOS this thing is possible.
You can do this but just keep in mind, that Background App Refresh is enable in device.
For more details, look into this link
https://www.urbanairship.com/blog/watch-list-ios-8-opt-in-changes
I hope you get your answer from above link
I am from Apple world, so I don't have much experience with Android.
But what I am looking is a way that Android devices receive push notification, without using any third party servers. Notification need to be standard Android notification (look and feel)
The reason I need this is, because I would need this in a room that does not have access to outer world. (can't connect to any server) But I have my own WiFi so users can receive push notification from my server via my wifi.
I know that on iOS this is not possible, what about Android?
it is possible using Service left running in system (background) after app exit. some samples HERE, you should be interested in START_STICKY flag
you have to keep some connection (socket?) or interval requesting (not so well, but possible) inside your Service. Google Services (including Firebase) does that by itself and "redeliver" received push messages to properly declared (in manifest) app
I'm developing viber like application using the ionic framework.
I want my app to be able to receive calls even when its on the background, just like whatsapp, the incoming call screen will pop up even if whatsapp is on the background or even when there is no instance of it at all.
I wasn't able to find anything about it.
I'm afraid there's no other way to achive this, then using Google Cloud Messaging (GCM). Although there may be other services that do the same.
When using GCM, your app will be notified with a notification even if it is not running.
But be careful! As your using Ionic, you will most likely rely on a cordova plugin to receive the notifications that are pushed to your device via GCM.
It depends on the chosen plugin how it handles the incoming notification.