I'm learning flutter, and I'm trying to make an app interacting with a Rust server.
I've done a bit of things already, all the basics of http requests, and simple menus and displays.
Now I would like to take it a bit further, and have the server send notifications / messages to the app even when it's closed. So idealy, I would like to have a web socket connection between the app and the server.
I've looked up some things, especially this already :
flutter : push notifications when app is closed
Executing dart in the background
But I can't wrap my head around it all.
How would one keep code running in the background ?
Any explanations on how it all work would also be great !
Related
I've been running through this for along time and i'm still stuck.
I'm working on a chat app using Flutter/Dart that it's based on Websocket .
I would like to keep the state of a connected user alive even if he terminates the app.
At this moment :
Foreground : Fully working
Paused : Fully Working
Background : Fully Working
Terminated : Not Working
I'm using Websocket_manager as a package to help
Thank you for your time.
I think this is not possible, you can try something like Firebase cloud messaging (link here), or something similar.
I'm working with FCM for the notifications and sometimes when the app is terminated and phone is locked.
it doesn't receive notifications.
I don't know what i should use right now :/
I am working on same solution, trying to keep app in the background - similar to what is Viber, WhatsApp, Signal etc doing. If I get it working, will share complete project. I have setup FCM google messaging and next bit is to have websocket. It does happen that notification from FCM does not go through.
If someone can explain how Viber, Signal and other can keep apps running and with 99 or 100% delivery rate.
UPDATE:
I have not try this yet but looks promising https://github.com/ppicas/flutter-android-background
And HowTo:
https://medium.com/stuart-engineering/keep-flutter-running-background-on-android-6ffc85be0234
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.
Preview:
I am using juggernaut chat server.I am having redis and juggernaut server running on machine. I am able to do chats within my local network on vaious web browsers. Everything is working smoothly. As juggernaut is a server driven chat server so i am quite sure about the scalability thing. Now here is the thing:--
Whats the problem:
I want to have a iphone native app too where user can login and chat with his friends. Now the thing i want to know is how do I push on iphone app, cause for juggernaut client registration a javascript code is needed. Something like this:
var jug = new Juggernaut;
jug.subscribe("channel1", function(data){
alert(data);
});
Basically how do i push new notifications to Iphone chat window. I don't know much about iphone as I am web developer. Still from google search etc I came to know some possible ( may be) ways:-
We can embed a url in iphone window. Is this a good approach?
Other thing we can do is using UrbanAirship kind of services we can do push notifications. Will push notification works for chat? I don't know about that even.
Third option can be polling. Iphone chat client keeps on hitting my rails app for new notifications. But i think this will be a very bad approach.
What are the other possible solutions?
Can any iPhone/Android developer guide me what should i do. I will eventually hire a Iphone developer to do all the coding part. But I want to have a big picture in my mind so that I can provide a complete docs of all the things, and have a clear picture how I want to discuss things with him before writing down the code.
PS: I am looking for a solution which works for android/nokia devices too. Cause later on I will be developing an application for that too. Basically it will be good to have a same solution. if not then compatibility factor should be there atleast.
Apparently there is WebSocket support in MobileSafari on 4.2 (source). You could probably write up a client that uses an embedded UIWebView to marshall the events to/from the Juggernaut server and deliver them to your app via shouldOpenURL and custom handlers.
You might also look at libPusher by Luke Redpath for interacting with push communication via the Pusher web service.
Check out this library: https://github.com/fpotter/juggernaut-cocoa
It's really easy to use.
I'm doing research for making a chat based app for the iPhone (it's not really text chat in the regular sense, but the principles are the same).
Maximum 6 people can be logged into the same chat room at any one time, and the most basic question is how to efficiently check for new messages?
Would I need to simply poll the server periodically? Or is there a way I could trigger an event on the phone from the server whenever there is some new content to pay attention to?
If having to poll all the time, I worry about the resulting lag as each participant will have to wait longer for others before they can post their own responses to others. And, potentially it might also be too much to handle for the server to respond to lots of requests all the time. It would also waste bandwidth, which is not free for the user...
Unfortunately I will not be able to set up a socket server for this app, it has to be based around a regular LAMP configuration.
I think you can either go with push notifications, or XMPP (Jabber) server.
XMPP will allow your iphone app to receive data even when in the background using the new multitasking features (listening for a socket), and i'm pretty sure you should find ready to use servers for LAMP (or at least open source implementations).
Note that the iOS4 multitasking API doesn't support polling in the background, so your only other option should be push notifications. If you're new to push notifications, you can maybe use a service like Urban Airship that might make the process easier.
XMPP sounds good for you idea, i think this is the best technology for Chat. It alos works great in iOS apps.
Maybe this code sample will be helpful to start using XMPP in iOS app - look at this QuickBlox Chat code sample. It demonstrates how to integrate 1-1 Chat, Chat in room into your android application. Also there is guide how it works. I think there will be no problem to integrate it into your application. Otherwise - Comments system below allows to ask any question you want and get fast answer.
Also there is Demo video http://www.youtube.com/watch?feature=player_embedded&v=SncQaJBBW_0 how this Chat works.
In my opinion the best solution is socket, but you say that you can't implement the server side for this.
You could also implement it with push notifications. You can receive the push also when your app is running and send all the data you need inside the push. Usually chat messages are short...
If you don't want to mess with push notifications on the server then the only thing left, as long as I know, is the polling.
A large part of a project I'm working on now deals with sending certain messages, which can easily and preferably be XML, from an iPhone app to a Ruby On Rails app. The webapp will have to instantly show these messages, so reloading the page isn't really an option.
I've been unable to find any info re: creating this sort of listening process for a POST request, can anyone guide me in the right path, and perhaps shed some light on what I should be doing, if I am overlooking something?
edit: Would using sockets be smarter? The apps will be run from iPod Touches/iPads in the same wifi network.
Thanks!
What you're trying to accomplish is doable, but certainly not one of the strengths of Ruby on Rails. If you need to update messages in the browser in realtime you can use JSSockets. But you need a server backend that is able to deal with lots of persistent connections like nodejs or if you prefer to use ruby EventMachine. If you still want to receive the messages via your rails app, the flow of data would be
Rails app receives the Message (say by POSTing XML to /messages)
The rails app posts the message into a message queue. Have look at resque
The Evented server listens to the queue and posts messages to the browser
Update:
Sorry, I misread your question as the iPhone app being only the sending part. Unfortunately you can't use JSSockets on the iPhone as it comes with an Adobe Flash component for communication. However, you still have the option of using long polling or implementing the socket in Objective-C and pushing the received objects into your webview via [webview stringByEvaluatingJavascriptString].