How to implement push notifications in React Native when the app is closed - reactjs

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 ^^

Related

React JS (not native) is there a way to create an external timer to force log out a user even after the window is closed?

Right now, I am using the react-idle-timer library to log a user out after a period of inactivity. However, when I close all tabs or windows associated with my application and wait the idle period, then open up the webapp again, I am still considered an active user. I want to find a way to log a user out if they close the webapps after a certain period of time.
I tried using react-native AppState, but I started my app with create-react-app and I am having issues getting the application to react native.
Any advice?
If your user closes the browser tabs/window, it is like they are killing a process using the task manager: The application has no running instances anymore and there is no possibility to prevent this from happening. Therefore, it is not possible to achieve such a log-out mechanism using a client-side approach.
However, there are some possible solutions to this requirement to log out a user upon inactivity, which highly depend on the authentication mechanisms you use.
If your app is frontend-only (and has no dependencies to any backend services), you can have a „last active“ timestamp in local storage, compare and update it on each action and invalidate the users credentials if necessary.
For session-based log-in, you can make the session expire when the user closes the window (which should be the default behavior). Additionally, you can add a session variable similar to the „last active“ field, which is updated on each action and invalidates the authentication state from server side if necessary.
If you are using token-based authentication, you can tweak the token expiration period and regularly re-issue a new token (probably not best practice, but might be working…)
In general, in terms of security, you should always prefer relying on information saved on the server-side of your app rather than on the client-side. Information in the browser can be easily manipulated by an attacker, while checking for a forced log out on the server-side even works when the user decides to hard-reset their machine (or experiences a power outage, …). And if your server-side is not working anymore one day… well, then you have some bigger problems.
Regarding react and react-native, though they are working pretty much the same and are using the same framework paradigms, they have one major difference: They are compiling for different platforms. Therefore from my experience and from their technical foundation, it is neither easy nor recommended to use components of one of them for the other one. So it highly depends on your use case which of them to use best.
Even though this is not a safe & sound solution, I hope to give you some orientation on your possibilities for such a log out.

apirtc, Receive calls in the background or minimized the app

How to receive calls when the app is in background or quit state?
They are two different states of the app, background and completely closed.
or because example:
"How to receive calls with apiRTC as does WhatsApp?"
I am implementing ApiRTC JS SDK
Hi ApiRTCSupport and HardcoreGamer I am one of the developers in charge of the integration process of APIRTC with the application that ian mentions, actually we already communicated directly with APIRTC support and they mentioned that we should ask the respective question here.
the overall picture is as follows:
We have the application fully functional and integrated with the API/SDK JS.
The application is developed in Ionic with Cordova
Ionic#v4
CordovaCLI#10,
cordova-android#10.1.1
cordova-ios#6.2.0
The minimum necessary plugins were installed (including cordova-iosrtc)
Now the integrated p2p calls and p2p video calls are fully functional and without problems.
Now, among the new requirements are:
The possibility of receiving incoming calls and video calls when the app is in background (minimize state), what happens is that when the app is minimized the websocket together with the execution of the JS code is completely interrupted, so for another user who wants to call the one who put the minimized app says "user is offline", we need the guide on how to handle this first use case.
Second requirement the possibility to receive calls and video calls when the app is in quit state (app killed) [ like Telegram, WhatsApp, Messenger, etc], so it should be able to receive the notification and allow to execute the JS code that would allow the connection with the apiRTC services/servers. in this case we have already investigated about VoIP(for iOS) and push notifications with high Priority(for Android), but we wanted to know if this is the way to go or you have a different implementation for ApiRTC services.
Thank you and really sorry for the little information provided at the beginning.
If you need any more specific information I will be waiting for your answers.

iOS11 location update after getting killed by user

I'm implementing a non VOIP app in iOS 11. As per the nature of my App, I've implemented the startMonitoringSignificantLocationChanges(). All the implementation went well and it is working now.
while terminating the app I'm calling startOrReStartSignificantLocationUpdate()
and I'm restarting significantlocationupdate in didFinishLaunchingWithOptions
also I'm updating location in server in didUpdateLocations event
Location updates is reflected on my server when the App is in foreground or background. It is now reflects even if user kill the App manually. So it works with SLC but
the problem is;
Updates seems to get stopped after a period of time say, 3 - 4 hours. It happens if the user kills the App manually. As per the nature of my App, I need to get it re-initiated up on location change and get the location update to my server.
Is there any category of App which can get this location updates forever in iOS11? I'm thinking about how Moves App in iOS works. Not sure it works perfect with iOS11 though
If you only use “While Using” location access, as far as I understand nothing changes for you. If you use the “Always” access though, and you didn’t provide a “While Using” fallback as you should have… well, you will need to do that now
As Brad Jensen explains in the WWDC talk I mentioned, Apple has decided that forcing the user to give the app “Always” location access is a bad user experience:
Now, a second reason we think that many developers choose to require
Always authorization is they’re simply trying to give their users the
best possible experience (…) but this makes for a very poor user
experience for the users that don’t wish to grant the app Always
authorization. They are forced to choose between granting the app
Always, which is more than they would like in this example, or
granting it Never, which means they don’t get to benefit from any of
the app’s location-based features. And their final option is to grant
it Always and then revoke that authorization after they’re done using
the app. In any case, the user is not having a great time with this
app.
So, when you build your app using the iOS 11 SDK, you are now required to provide an NSLocationWhenInUseUsageDescription key in all cases (if you use location at all). For “Always” access, you can additionally provide a second key, which is now called NSLocationAlwaysAndWhenInUseUsageDescription. If you only provide NSLocationAlwaysAndWhenInUseUsageDescription but not NSLocationWhenInUseUsageDescription, asking for “Always” access will not work:
This app has attempted to access privacy-sensitive data without a
usage description. The app's Info.plist must contain both
NSLocationAlwaysAndWhenInUseUsageDescription and
NSLocationWhenInUseUsageDescription keys with string values explaining
to the user how the app uses this data
Effect on existing apps
Most SDK changes usually only take effect once you recompile your app with the latest version of the SDK & Xcode. This one is different: even if you don’t release any updates this summer, this change will affect you.
Here’s what the user sees when they run existing apps from the App Store in iOS 11 beta and they ask for location access:
The first one is from Foursquare, which has provided both access level options for a long time. In this case, iOS 11 lets you immediately choose “While Using” or “Always”, and since the description texts have not yet been updated with the new behavior in mind, it shows both texts at the same time.
The second one is from Topo Maps, an app that lets you browse hiking maps and find yourself on the map while you’re on the trail. You can imagine it has no reason to track you in the background, but still, the developer has not provided a “While Using” option. iOS 11 now lets you choose that option anyway, but since it might possibly cause some unexpected behavior in the app, it shows a warning that some parts of the app might not work.
If your app has only provided an “Always” key so far, I’d recommend that prepare a transitional update that adds the NSLocationWhenInUseUsageDescription key and makes sure the app works properly in this mode. That way, the user will get a popup like the one in Foursquare, which at least looks less scary.

Queue publish calls with PubNub when offline

I'm dabbling with using PubNub for various parts of my app. I'm using their AngularJS library for this.
Right now, I'm just testing it for doing "analytics". Basically, I want to track ever more a user makes in the app - buttons pressed, states navigated to, etc. So, I track actions and publish on a channel.
It all works great - when the user is online. However, when offline, I lose all this tracking. I was sort of hoping that PubNub client would automatically queue all the publish requests. It does not seem to do this.
So, I'm thinking I'll have a service to collect all publish requests and put them in a queue if the device is offline. Once the device is back online, I'll publish any queued requests.
Is this the best approach? Does anyone have a better suggestion? Does PubNub already have this ability and I'm just not finding it?
Yes, currently, this is the best way to achieve this.
There are different scenarios for queuing / retrying, for example -- depending on the content of the message (eg expiration/timeliness of the message), and depending on the reason (no internet, channel permissions) you may want to re-queue/retry some and not others, etc.
So if you can implement your own retry logic custom to your use case, thats ideal. We may provide more productized options on this moving forward...
geremy

DevExpress - Show Alert Window for all users in app

We've got a program that runs on our network (it's published to our app-server and run from there as well) and I'd like to show an Alert window (by DevExpress) to all users who are running the app, whenever a new item is entered. Obviously the code would go in the Save event but when I put it in there, it only works for me, meaning I'm the only user who sees the alert, no one else. The same can be said for other users...they only see the alert when they enter it, not when someone else enters it.
Any ideas as to how this can be accomplished?
You can use straight MSMQ to put on a message and have clients listen on that queue. You can also use NServiceBus (which does use MSMQ) that has a publish subscribe framework built in. This way your clients can subscribe to all clients or certain clients.
Since WinXP, Vista and Win7 have MSMQ it just maybe a matter of installation and configuration (which NServiceBus will do 'automatically' for you)
You could try with Comet if you want true push mechanism. Otherwise you could use periodical pull using setInterval and ajax calls. However, both techniques have some performance repercussions.

Resources