expo 개발모드에서는 push-notification이 기본적으로 잘되지만 배포를 한 이후에는 token을 받을수가 없다. 이유는 Firebase Cloud Messaging을 사용해야만 가능하기 때문이다. 따로 설정이 꼭 필요하다. IOS는 따로 설정필요없이 배포모드에서 사용이 가능함.
아래 블로그를 따라서 진행하면 됨.
https://velog.io/@tchaikovsky/RN-EXPO-FCM%EC%9C%BC%EB%A1%9C-Push-Notification-%EB%B3%B4%EB%82%B4%EA%B8%B0Android
없는 부분은 expo 공식문서의 설정 부분을 추가로 해줘야 함.
요점은
1. google.service.json 다운로드 (firebase console)->root파일에 복사 후 app.json이 등록
2. cargo4u-android-7b478957ee51.json 다운로드(google cloud)->root 파일에 복사 후 eas.json에 등록
3. Cloud Messging Api enable 시키기(google cloud)
4. FCM server key 찾기(firebase console)
5. expo.dev 에 2번과 4번 찾은 것을 등록하면 완성
#1. google.service.json 파일 다운로드
어디서: firebase console
Firebase 프로젝트의 정보가 담긴 google.services.json 파일
해당 파일은 파이어베이스 콘솔 - 프로젝트 개요 옆 톱니 바퀴 - 프로젝트 설정으로 들어가셔서 중단의 내 앱에서 다운로드가 가능합니다.
다운로드 후 프로젝트 폴더의 루트에 저장한 뒤, app.json에 "googleServicesFile": "./google-services.json"를 작성합니다.(Expo에게 위치를 알려주는 값)
app.json
"android": {
"versionCode": 18,
"adaptiveIcon": {
"foregroundImage": "./assets/logo.png",
"backgroundColor": "#FFF"
},
"googleServicesFile": "./google-services.json",
"package": "com.enesdyaz.cargo4u"
},
#1. google-service-account-key 파일 다운로드해야함. ([projectid]-651ec22743334.json 형식임)
어디서?: Google Cloud Console
https://console.cloud.google.com/iam- admin/serviceaccounts/details/118422818292476912812/keys?project=cargo4u-android
중요사항: 프로젝트 이름: cargo4u-android, 프로젝트 이름이 모두 동일해야함.
새키를 만들게 되면, 파일을 다운로드 받게된다.
다운로드 받으신 JSON 파일을 프로젝트의 루트 폴더에 저장한 뒤 eas.json에 submit.production.android.serviceAccountKeyPath에 파일의 위치를 저장합니다.
eas.json
"submit": {
"production": {
"android":{
"serviceAccountKeyPath": "./cargo4u-android-7b478957ee51.json"
},
"ios": {
"appleId": "enesdyaz@gmail.com",
"ascAppId": "6444356206",
"appleTeamId": "X3XCHZ6F4A"
}
}
}
#2. Cloud Messging API/Google Play Android Developer APi 를 등록해야 함.
어디서 : Google Cloud Console
#3. FCM server Key 찾기
FCM server key는 어디에? Firebase console
https://console.firebase.google.com/project/cargo4u-android/settings/general/android:com.enesdyaz.cargo4u
** Cloud Messging API(기존) 이 disabled이 되어 있다면
expo 공식문서에서 나오는 내용처럼 하면 됨
Server Key is only available in Cloud Messaging API (Legacy), which is disabled by default.
Enable it by clicking the three-dot menu > Manage API in Google Cloud Console and following the steps in the console. Once the legacy messaging API is enabled, you should see Server Key in that section.
#4. 웹사이트 https://expo.dev 로 들어가서
In your Expo account's dashboard, select your project, and click on Credentials in the navigation menu. Then, click on your Application Identifier that follows the pattern:com.company.app.
For Legacy Application Identifiers, run expo push:android:upload --api-key your-token-here, replacing your-token-here with the string you just copied. We'll store your token securely on our servers, where it will only be accessed when you send a push notification.
Under Service Credentials > FCM Server Key, click Add a FCM Server Key > Google Cloud Messaging Token and add the Server key from step 3.
Google Service Key 와 FCM server key를 입력하고 저장하면 마무리가 됨. 배포후 테스트해보세요.