<aside> 💡
</aside>
다음 문서를 통해 FCM을 설정하세요. 기존에 이미 FCM을 사용하는 경우 다음 단계로 이동하세요. https://rnfirebase.io/messaging/usage
<aside> 🚨 한 번만 다운 받을 수 있으니, 안전히 보관해주세요.
</aside>
BuzzBooster의 Push Notification을 처리하려면 다음과 같이 작업하세요.
Push Notification을 수신하기 위해선 Android 13 이상과 iOS에서 유저의 권한이 필요합니다.
react-native-permissions 등의 라이브러리를 활용하여 각 플랫폼에 맞는 권한을 요청하세요.
import messaging from '@react-native-firebase/messaging';
import { BuzzBooster } from 'react-native-buzz-booster';
const token = await messaging().getToken();
BuzzBooster.setPushToken(token)
import messaging from '@react-native-firebase/messaging';
import { BuzzBooster } from 'react-native-buzz-booster';
/**
* 앱이 실행 중인 상태에서 Notification 처리
*/
messaging().onMessage(async remoteMessage => {
const data = remoteMessage.data
if (BuzzBooster.isBuzzBoosterNotification(data)) {
BuzzBooster.handleForegroundNotification(data)
}
});
/**
* 앱이 종료된 상태에서 Notification 클릭으로 시작될 때 발생.
*/
messaging().getInitialNotification().then(async remoteMessage => {
if (remoteMessage == null)
return
const data = remoteMessage.data
if (BuzzBooster.isBuzzBoosterNotification(data)) {
BuzzBooster.handleInitialNotification(data)
}
})
/**
* 앱이 Background인 상태에서 Notification 클릭으로 시작될 때 발생
*/
messaging().onNotificationOpenedApp(async remoteMessage => {
console.log("onNotificationOpenedApp")
const data = remoteMessage.data
if (BuzzBooster.isBuzzBoosterNotification(data)) {
BuzzBooster.onNotificationOpenedApp(data)
}
})