I'm trying to build a web application based on React.JS (not React-Native) and Django for its backend. I'm struggling right now on how to send push notifications on a specific time. Are there any useful modules/APIs that can support time based push notifications?
To be exact... even if I exit the website, as long as my browser (ex: Chrome) is on, I want to still be able to get a notification at the time I set.
Firstly the Front end framework is not much relevant , secondly you could use firebase push notification , generate a client side token for that browser and send it to your DB and store it, then you can use something like django-cronjobs and time it when you want a push say at 5 pm UTC on every day , set it there and in that you can use fcm to push notification to it.
Ref this github repo for fcm django you just need to put django-cronjob code to trigger that file.
Related
I have a PWA built with ReactJS and I have the NetworkFirst policy handled by Workbox, so when I update the front, the service worker detects a new version and download it in the background and this new version is applied only in two cases: when the browser is closed and opened or after 24 hours.
The problem comes when I need to change something in the API (django), for example I change the name of an endpoint and I need to change in the front too. When that happens, I make the release in both, front and back, but with the PWA if it last one day to make the update, during this day the app will be doing calls to an "old" endpoint so it will not work.
I would like to know how to handle this, a newer version of the API when the PWA is not updated yet, or if it is posible to force an update of the PWA when required.
Thank you in advance!
Only make backwards compatible changes to the API. For example you have API v1 (example.com/api/v1/endpoint) deployed, deploy v2 (example.com/api/v2/endpoint) and new frontend that uses API v2. After some time has passed and usage of API v1 has stopped, delete it and have a new backend deploy.
I am answering my own question here in case anyone runs into a similar problem.
I recently have been working with GoNative to spin up a hybrid native application for DoneDone, a task management and shared inbox tool.
I am also using OneSignal's push notification integration with GoNative to handle native push notifications to the user. In addition, I am sending out push notification messages from the server-side (C#/.NET in my case, but the server-side platform is irrelevant here).
I have already set up the necessary files to get universal links to open up in the native app rather than the browser (e.g. the apple-app-association-file). I am getting push notifications created and sent correctly.
However, I cannot get the push notification to link to a specific page on the application via the server-side API.
In OneSignal's Create Notification API doc, it seems like you would send across either the url, web_url, or app_url parameter in your JSON request. However, none of these work correctly if you are using GoNative's push notification integration with OneSignal.
For instance, if you use the url or app_url parameter, you get a secondary browser pop-up inside your native app, instead of a load from just your native app.
You need to set your own url value in the "Additional Data" property of your push notification. GoNative has documentation on this if you are creating push notifications from within OneSignal's web platform, but not specific guidance if you are programmatically creating push notifications via their API.
To do this via JSON, you add a targetUrl value to the data property.
{
"app_id":"3baaa656-8832-4733-a88b-b83aba2598a7",
"include_player_ids":[
"3baaa656-8832-4733-a88b-b83aba2598a7",
"3baaa656-8832-4733-a88b-b83aba2598a7"
],
"headings":{
"en":"DoneDone Project"
},
"subtitle":{
"en":"#123: This is a bug!"
},
"contents":{
"en":"Ka Wai Cheung created the task."
},
"data":{
"targetUrl":"[LINK TO THE WEB APP]"
}
}
Once you specify the targetUrl, it works. I hope this saves someone time one day!
This apps closed but services are running. How can i do this on react-native?
I would like to make services that listen my app notification.
You can use react-native-firebase package for this specific purpose.
Way 1 - Data only notification
Check out the data only notification section documentation here. Please note that this would work only on android.
Way 2 - Notification + Data
Send a notification and when user presses it, update the data of the application. This should work both for android and iOS. You can send key/value pairs in your notification and send a type as one of the key/value pairs. Now, when you handle the notification based on this type you can can API's and update data as required. You can read more about it here
I'm studying React Native right now, and I'm trying to figure out how to enable the reception of Push Notifications even when the app is closed, just as Facebook does.
I'm a web developer, so I'm not used to mobile apps' "Manifest" logic. Where should I start from?
Thank you!
It seems that since you are a web developer, mobile app is not yet familiar with you. Actually, setting up push notification will require a few more official steps (differently on iOS and Android), and after everything is set, the push notification will happen between Apple server (or Google server) and smartphone's OS (which is iOS or Android), so the push notifications will come to the phone no matter what (without knowing/caring your app is opened or closed ^^)
In the programming code of our app, we can do our logics when the notifications come based on 2 cases: users is using the app or app is not running (not running means users are not using your app, and it is either staying awake in the background or users have exited it completely - e.g. pressing Home button twice on iPhone, and swiping the app away)
Actually, If you want your app to stay awake in the background, you can add some settings to the "manifest"-like files (of course differently on iOS & Android). However, my experiences taught me that keeping the app awake will encourage the users to complain and delete our app (my previous app's user once complained about his iPhone's battery was consumed greatly because of my app ^^)
If you really want to keep your app awake, you can set it in the settings, then in the push notifications' data, you can include extra parameters, and finally in the function of receiving push-notifications in your app, you can do anything with those parameters!
In short, you may just need to config push-notification properly for your app, and Apple/Google will do the rest, either your app is running in background or totally closed, it will receive the notifications. Hope you can find a good solution based on my explanation. If there's still something unclear, feel free to post here some more details on your needs, thanks!
This is the library I'm using with my previous react-native project: (they also have tutorial there ^^)
https://github.com/zo0r/react-native-push-notification
ADDED EXPLANATION: (based on author's needs):
The goal is: the user will register/login in the app, and will subscribe to some future events.
=> whenever users open the app, data will be sent to Apple/Google server to get a token, and you will use this token together with user's subscribe data to send all to your own push-server (you can use PHP or node.js server or whatever)
When an event gets updated a notif. should be sent to all the users who are going to that event. So a notif. aimed to certain users only.
=> like the above answer, data will be sent every time users open app (or change settings, you can do it in your logic of the app, because data will be kept your own push-server, which means on that server, you can even see user list, and can aim to certain users - it depends on what data will be sent to the users from the smartphone, but users may refuse inputting too much information like name, age or email, but it's up to your service's need ^^)
By clicking on it, the app will open and a certain page of the app (pre-existing) will be shown.
=> by default, when an notif. is clicked, the app will be opened for sure, and here once again, you can add extra parameters to the notifications (which is the landing page you need, then in the function of you app, just go there - but it may get extra logics for this. Besides, when to push notification, and which data should be pushed etc. will be controlled by your own server)
It seems like the most complicated part will be the "sending to certain users" one!
=> I explained this already, but you're right, actually it's complicated, because you need to create your own server with lots of API and logics based on your needs, and it need a few more steps (complicated one because you need to register many things with Apple & Google, then adding their Certificates into your own server etc.)
Hopefully you will achieve it, I suggest you play around and truly understand how push-notifications work first (for both sides - your own server and your application) - Good luck, though ^^
I am working on new project to display an online stock price screen for a user. We already have this in a combination of php, MySQL and AJAX, but it is very slow and lots of requests are generated on the server. So I want to change the technology.
I have the database in MySQL. One process is already updated: the last price of stock in my database. I fetch those records and display them in the screen. After searching Google, I feel I have to use socket.io, node.js and angularjs. After this I am planning the following:
Front End in angular.js
Socket.io with nodes.js
Nodes.js
Restful API call initiated on nodes.js every 10 seconds for page.php. This page will fetch all symbols of market (around 1000) from the MySQL database and send back a json object. (Can I directly call a MySQL query from node.js and received the json object, and will this reduce the php in-between?)
Socket.io emits this query to every client connect on the site.
Then the angular front-end will display only the symbol which is selected by the user and highlight the changes on the screen.
I have the following problems, as I have limited knowledge of the above technologies.
How do I receive the json object from socket.io into angular.js?
How can I make the logic in the angular page to display only the symbol which user selected from a 1000 symbols response and highlight the change price field only?
How will I connect three and server with MySQL or php?
One thing is read for middle ware i can use the expressJS.AS I want my front end in AngularJS how can i fit the express in between Angular and socket.io and node.js
You need to include socket.io client code on your site, and here is a good example how to turn an external library like socket.io into a service http://www.html5rocks.com/en/tutorials/frameworks/angular-websockets/
I think that the best solution here would be to subscribe via socket.io only the element user wants to see i.e. websockets for selected element and pooling every minute or so for other elements to not generate that much of a traffic on sockets
user opens element A
socket.emit('subscribe', {add: 'A'})
then user switch to element B
socket.emit('subscribe', {add: 'B', remove: 'A'})