Cannot register device with TalkJs for push notifications - react-native

I am working on a React Native app that uses TalkJS. We want users to get a push notification for every message they receive. The messages are going through but we aren't getting notifications. We have uploaded our .p12 to the TalkJS dashboard and followed the docs for setting up a React Native project. Below is the relevant code we're injecting to the TalkUI loadScript. We followed https://talkjs.com/docs/Features/Notifications/Mobile_Push_Notifications.html
const res = await window.talkSession.registerDevice({ platform: "ios", pushRegistrationId: "${deviceToken}"});
alert("registering deviceToken ${deviceToken} response: " + res)
We are getting the alert with the correct deviceToken but this method does not return anything. We tried .then and an error first callback but nothing is coming back from this method.
Edit: this method is not designed to return anything, so the response is expected to be empty.

The Promise was designed to not return anything as Kapobajza mentioned.
From their support chat: "We have an issue regarding push notifications on iOS when using React Native."
Edit: this issue has been resolved. In addition to work that needed to be done by the TalkJS team, push notifications require a user to have a 'role', as is very loosely implied in the Overview for Push Notifications

Related

OnNotification() function dosen't work when i send localNotification

I am using react-native-push-notification to implement push notifications, I have followed the documentation properly when I send remote notification OnNotification() get called properly but when I send LocalNotification using PushNotification.LocalNotification() I get proper notification pop-up but it doesn't trigger OnNotification() function, I have gone through lot of stackoverflow questions and git issue still no solution, can anyone have solution have on this issue that would be great help
For ios this method will trigger/callback when you click on the notification and launch the app from killed state
PushNotificationIOS.getInitialNotification().then(notification => {
if (!notification) {
return;
}
});
I just implemented and tested in release mode, it worked well. For Andriod i'm still figuring it out which method triggers the call back in killed state.
Note: Above code works only in release mode for iOS.

Is there a way to attach console.log to firebase analytics event?

I am setting up firebase analytics for my React Native app. Is it possible to attach a console.log that fires each time firebase.analytics().logEvent() is called? I want to be able to see the event name and params in the console.log. I know I can check in the DebugView in Firebase, but just having it logged to the console seems a bit faster. Appreciate any input.
Per the comment, it would be more economical to create a global method that sends the data to Analytics and console together.
You can read about Global Helpers HERE.
module.exports = function(payload) {
firebase.analytics().logEvent()
console.log(payload);
}
_.Log(payload);
This allows you to also introduce filters and edge-case scenarios within your app as needed including debug mode and alerts from within your app.

React Native Expo app how to unregister from Notifications

In my react native expo app I am successfully registering to the notification service with Notifications.getExpoPushTokenAsync() and it is working without issue, my question is, how do I stop receiving notifications? Is there a way to clear the push token on the device only?
The problem I am having is if a user logs out and a different user logs in on the same device, they will still receive the previous users notifications since the device still is still registered. Notifications.removePushTokenSubscription() seemed like it may work but it only removes the push token listener created with Notifications.addPushTokenListener() which (I think) is unrelated to this issue
My current logout function attempt looks like this:
const logOutUser = async(notificationToken) => {
if(notificationToken){
var subscription = await Notifications.addPushTokenListener(notificationToken);
await Notifications.removePushTokenSubscription(subscription);
}
}
Am I thinking about this problem wrong? Thanks!
You can't unregistered from Notifications, there is no function that does that simply because the expo token is related to your device,not your account, instead you can do this:
When user login you should send the expo token to your back end
and store it in an array of expoTokens, because user can have his
account open in multiple phones.
Store the expo token in your
AsyncStorage.
When the user logout you should delete the expo token from array of expoTokens array in your Backend Database.
and finely delete it from AsyncStorage .
Hope it works for you!

React Native Linking Listener?

Description:
Built an app, need to implement Swedish BankID. This means, when user presses a button, the Swedish BankID App opens, and when the user has signed in, the Swedish BankID App sends the user back to my app (which it does automatically), in which I need to retrieve data (if sign in was successful or not).
What needs to be accomplished:
Open Swedish BankID on the device from my app. Need to be able to receive a payload from Swedish BankID App in my app (Swedish BankID sends user automatically back to my app).
Current Code:
const url = `https://app.bankid.com/?${autoStartToken}`;
const supported = await Linking.canOpenURL(url);
if (supported) {
const answer = await Linking.openURL(url);
} else {
Alert.alert(`Don't know how to open this URL: ${url}`);
}
Currently, the Swedish BankID App opens correctly, my question is, is there any way to receive data from the other app? I know this is possible with Native Modules (running Objective-C etc), however I am using Expo Client and do not wish to eject.
I have yet to find anything that suggests that React-Native can listen to the other app.
You can use expo WebBrowser to open url.
For authentication you will want to use WebBrowser.openAuthSessionAsync, and if you just want to open a webpage WebBrowser.openBrowserAsync
Exemple:
...
import * as WebBrowser from 'expo-web-browser';
....
const handleLinkAsync = async () => {
let result = await WebBrowser.openBrowserAsync('https://google.com');
console.log(result)
};
Since the BankID app can even be on another device (if you present the url as a QR code) it's kind of hard to communicate with the app. Also, from a privacy perspective the app isn't supposed to give a lot of information away.
What you can do is to "bounce" information via the app using the "redirect" parameter. That's especially useful when you want to tie back to the existing session. There are however a few caveats, especially when using multiple browsers, so make sure to read the Relying Party Gudelines.

selecting react native push notification

I am using react native and trying to add push notification.
My application need push notification because of chatting. I just need push notification to appear whenever the user receives chat message.
I've searched couple of libraries about push notification and found out firebase and react-native-push-notification.
Which one is proper library for this case and please tell me if there is other better way to solve this problem.
We're using invertase firebase notification library which is working so far better without any issues.
You'll get almost all the options which you needed for push notification customization like badges, etc.