How to make periodic background fetches in Flutter iOS and Android App? - flutter

I am developing an app that should fetch an API periodically (every 15 or 30 minutes). I am using Flutter for the frontend development. The app should be available for both Android and iOS devices.
The background task includes a call to the backend. In the backend, a worker is determining certain data (this can take up to one minute) and sending it then back to the frontend. The task has to be (at least partially) initiated by the frontend, as an decryption key is passed to the backend.
I had the idea to use Firebase Cloud Messaging to push the requested data to the devices. Unfortunately, it seems to be necessary to have the Apple Development Program enrolled to use it. As the app is an university project, and I'm not even sure, if the FCM approach is the best one, I don't want to pay the 99€ for the enrollment.
Beside the FCM approach, I found some flutter packages like "background_fetch", to pull the data instead of pushing it, which wouldn't be a problem for me. But all packages I found have the problem, that they work differently on iOS and Android, and are also not very reliable in terms of background task management by the respective operating systems.
Is there any "simple" solution for this problem, like a flutter package allowing me to schedule periodic background tasks on both iOS and Android, which is mostly reliable in that the time periode is respected at least roughly and the background task is not killed while waiting for the response? Or will I have to implement an own server-side Push-Service to avoid the costs for the Apple Developer Program?
Thank you in advance!

Related

Can Ionic 3 App handle 500,000 to 1M users?

I am building an App on Ionic 3.
How many users can ionic 3 platform handle?
Is Ionic 3 scalable to 500,000-1,000,000 users?
The App is a basic Progress Tracking Tool and a user is expected to open it 1-2 times per day for max 5 min.
Thanks!
Whether Ionic can handle it isn't the question here, it depends entirely on the foundations on which your app is built.
If your app requires connections to a single or multiple APIs and a full backend system, it will be how well your server can process those loads.
Each instance of an Ionic application will work perfectly fine if built correctly as they're isolated to the device in which it is installed. It's all the important stuff working in the background to serve content to your app which is important.
To provide a primitive example; imagine a social media app like Facebook or Twitter. Let's assume both apps are built to sensible coding standards. If you were to plug either of those apps in to a server that was essentially a dusty old box underneath someone's desk, the entire system would completely crash. There's no way it could handle all of the requests for information because the technology simply can't process it.
The reason they don't crash is because they have large-scale data centres, capable of serving millions if not billions of requests simultaneously - they have good servers.
Moral of the story:
If you're building an app, arguably for any size but certainly for 500K+ people, start with your foundations first. The foundation is the servers/data points which will serve your app. Build that correct, and your Ionic app will work perfectly fine.
Yes it can.
The app it self is self contained, your backend will be the bottleneck here.

Provide a Flutter WebApp from within an iOS Flutter app

I'd like to create a flutter IOS app which stores data and allows to edit it within the iOS app.
Then the iOS app be able to provide a webserver [start an internal webserver e.g. using jaguar] and serve a WebApp, which operates on the same data on the iDevice.
Idea: Make the iDevice the only data store. And allow a e.g. windows client to access the data on the iOS device using a web interface [and not require it to push it into a cloud].
I have used Flutter jaguar to make it work, have you tried to run the example ?
I think what would be very challenging is that IOS kill background processes, so to use your IOS app as a (reliable) server in the background would be impossible (if reliability, and it should, is a concern), only audio streaming apps would not be killed. So it means you will have to run your server at all time in the foreground
And not to mention that if your phone is out of battery it would also stop working (but of course, you are aware of that, and that's true that if connect to charger, it could perfectly act as a server, as I have tested myself!).
NB: If it's for some serious project, not a fun personal project/challenge, I advise you to reconsider and what you could still do is to manage your server data from the IOS app (meaning that you would send data on on-premise or cloud server like Firebase). But as you stated in your question you are looking to make it work on the Iphone device.

Flutter own push notifications (store agnostic)

I was wondering, given that Flutter is multi platform and each store requires its own procedure for the final step of setting up Push notifications, would it be worthwhile to implement a full "flutter proprietary push notification system" something that would ignore completely the Android/iOS and other stores implementation?
The main service that the store provides is to "find" the device in the final step of the push, this could be replaced with:
a subscribe / ack of this flutter layer to a server (whenever the app declares that it wants to use it), that will send the message when required (with a messaging queue?)
an always on instance on the phone to actually receive the push (this is probably the most critical part)
UPDATE: I am realising that this necessity will probably be covered by some sort of third party provider, such as what Crashlytics has done with error and crash reports.
Operating system push notification services (OSPNS) are provided by the Android and iOS and other platforms. If you want your messages to be shown as notifications on the notification tray/status bar you have to configure it as required by that platform and there is no other option for this. If you want to use only one push service than Huawei Push Kit might be the one to choose since it can send push notifications to all platforms Android, iOS, Huawei devices and also Web.
This is almost impossible.
Because on the basis of Android, there is a part handled by the OS in the case of push, so even if the app does not reside in memory, it can be processed. If you're going to create a Flutter-only Push system, the Flutter app should always be running as a background service (iOS is a different issue).
If you only want to be able to use push while the Flutter app is running, that might be the way to go. However, it will be difficult after the app is closed.
url link : https://developer.android.com/reference/android/app/NotificationManager

What's the best way to run a function after a request sent by a server?

Here is the use case:
the user launches the app and grants permission, the app connects to the server
at some point in the future, the server sends a request to the app
the app
regardless of whether it is running or not in the foreground or background, wakes up to run this code
Here are some options I have explored which I am unsure about:
server sent events
websockets
push notifications
Is there a reliable and safe way to do this on android, whether it's Kotlin or Flutter? Can you provide examples or documentation?
Thanks!
Turns out that the best way to do it is with push notifications!
Websockets and server sent events are better suited for other use cases. Persistent connections to a server are resource consuming, and both Android and iOS have mechanisms in place to terminate apps running in the background to save memory etc. So we would probably lose the connection and not be able to receive anything from the server if we minimized the app or locked our phone screen.
Push notifications are basically built for this exact use case because, even though they work differently on Android and iOS, they are built to receive messages from a server regardless of whether the app is in the foreground, background, or not even currently running.
I used Firebase Cloud Messaging to build my app since it's primarily an Android app. It worked like a charm.

How to get real-time notifications in Flutter

I am new in Flutter, I have used web_socket_channel in my app. Now I want to get notifications when the app is not running. Keeping the app running in the background is not possible, so what do you recommend me to do?
So far I found them:
Websocket Manager- They claim to open socket connection in the background, but I couldn't find enough resources to find out.
https://pub.dev/packages/websocket_manager
Background Fetch - Opens the app for a few seconds in the background periodically (15 minutes or more). I do not prefer this one actually :( .
https://pub.dev/packages/background_fetch
You can use firebase_messaging, it's easy to implement in android and got a bit of configurations to do in IOS but it's good.