Skip to content

Instantly share code, notes, and snippets.

@warodri-sendbird
Created September 2, 2021 14:54
Show Gist options
  • Save warodri-sendbird/1b0c544d1ff592d8b26b696e2850e0db to your computer and use it in GitHub Desktop.
Save warodri-sendbird/1b0c544d1ff592d8b26b696e2850e0db to your computer and use it in GitHub Desktop.
useEffect(() => {
AsyncStorage.getItem(savedUserKey)
.then(async user => {
try {
if (user) {
const authorizationStatus = await messaging().requestPermission();
if (
authorizationStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authorizationStatus === messaging.AuthorizationStatus.PROVISIONAL
) {
if (Platform.OS === 'ios') {
const token = await messaging().getAPNSToken();
await sendbird.registerAPNSPushTokenForCurrentUser(token);
} else {
const token = await messaging().getToken();
await sendbird.registerGCMPushTokenForCurrentUser(token);
}
}
}
} catch (err) {
console.error(err);
}
})
.catch(err => console.error(err));
if (Platform.OS !== 'ios') {
const unsubscribeHandler = messaging().onMessage(onRemoteMessage);
return unsubscribeHandler;
}
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment