React Native Expo app how to unregister from Notifications - react-native

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!

Related

Get Google Click ID (gclid and msclkid) inside React Native

Inside the web today, we are getting gclid and msclkid when user get's on the lending page from the google ad, with
const { gclid, msclkid } = queryString.parse(location.search);
And we are storing it inside the DB,
Now we want to do the same inside our mobile app too, when user intall the app from the ad we want to get those 2 values and store them inside DB
We are using Expo EAS inside the mobile project righ now, but I'm not that experianced with this marketign tools
Anyone know how this can be done?
Thanks!
I've tried getting it inside the product thru firebase analytics but it seems it's not working or I'm doing it wrong, I also tried this lib https://www.npmjs.com/package/react-native-advertising-id but it's outdated and it does not seem to pull data I need

how to store data in App even After User Logout and Close the App. in react native

Is it possible To store some data in App. Even after User logout it and close it from recent Apps.
if yes then How.
I heard About redux and redux persist. But I am not able to store data in app when I logout and close my app from recent app. So I dont know if I cant execute it properly.
is redux and redux persist really store data even after app logout and close from recent app ??
or is there another method or library for that..
I Build an app and used Expo.Sqlite as a data store.
I even build an ORM for it if you are interested I could post it here to.

Cannot register device with TalkJs for push notifications

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

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