FCM 토큰 변경하기

부가 설명
FCM 토큰 새값으로 변경
Tags
Push Noti
FCM Token
get

1) 권장사항

fcm 토큰앱 인스턴스별로 고유하다.
따라서 앱 토큰을 변경하는 방식을 택하는 것 보다는, 토큰을 관리를 잘 해야겠다는 생각을 하는 것이 바람직하다.
다시 말해서 프론트와 백엔드쪽에서 적절히 협의보고 fcm 토큰을 바꿀 일이 없도록 하는 것이 베스트다.
The FCM Token is an Instance ID token, it represents the installed app and not the signed in user. Generally once the app remains installed it will have the same token no matter what user is signed in. You would have to manage what user is associated to the token yourself. When the user signs in you should associate the token with the user's ID and when the user signs out you should remove that association.
 

2) fcm 토큰 새로 발급

바꿔야하는 상황이 '굳이' 생긴다면 바꿔야지. 방법이 어렵진 않다.

간단 예시

import iid from '@react-native-firebase/iid'; export default function App() { useEffect(() => { const getFCM = async () => { await iid().delete(); const FCMToken = await iid().getToken(); console.log('FCM토큰 : ', FCMToken); AsyncStorage.storeData('FCMToken', FCMToken); }; getFCM(); }, []); ... }

delete

delete(): Promise<void>;
인스턴스 ID와 연관된 모든 데이터 삭제.
인스턴스 ID가 생성될 때 부터 Firebase 백엔드로 정기적으로 데이터를 보내던 작업도 중단됨.

deleteToken

deleteToken(authorizedEntity?: undefined | string, scope?: undefined | string): Promise<void>;
이전에 getToken()에 의해 승인된 엔터티의 스코프에 대한 액세스를 취소함.

get

get(): Promise<string>;
앱 인스턴스를 고유하게 식별하는 식별자를 반환.

getToken

getToken(authorizedEntity?: undefined | string, scope?: undefined | string): Promise<string>;
앱 대신 작업을 수행할 수 있는 엔티티를 인증하는 토큰을 반환함.