Created
September 2, 2021 14:54
-
-
Save warodri-sendbird/1b0c544d1ff592d8b26b696e2850e0db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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