The operation couldn’t be completed. No APNS token specified before fetching FCM Token

고병찬·2024년 10월 22일

TIL

목록 보기
45/54

들어가며

어제 겪었던 문제를 해결해보려고 한다.
참고한 글은 여기 -> https://github.com/invertase/react-native-firebase/issues/6893

에러를 읽어보자

"before fetching FCM Token" -> getToken()을 호출하기 전에
"No APNS token specified" -> APNS token이 정해지지 않았다.

왜 FCM token을 fetching 하기 전에 APNS 토큰이 정해져야하는가

FCM는 APN을 통해 Apple 앱을 타겟팅하는 모든 메시지를 전송합니다. 🔗

ios 앱에 노티를 보내려면 APN(Apple Push Notification)을 통해야 하고

mapping your APNs token to the FCM registration token 🔗

그러기 위해 APNs token을 FCM token에 매핑해야한다.

그래서 APNS Token이 필요한 것이군
그럼 왜 APNS Token이 없지? 난 분명 알림을 허용했는데 그러면 APNS Token이 받아져야하는거 아닌가

No APNS token specified <- 왜 이럴까

이거 알고보니까 react native firebase 라이브러리 사용하려면 ios에선 따로 setup이 필요했다... 공식문서에는 저 에러에 대한 언급이 없는지 찾아보다가 발견함...
https://rnfirebase.io/messaging/usage/ios-setup

보니까 해야할게 생각보다 많았다
특히 이 부분을 빼먹은듯
https://rnfirebase.io/messaging/usage/ios-setup#linking-apns-with-fcm-ios

저기서 하라는거 다했다!
key 등록
App Identifier 등록
provisioning profile 생성
다했다!

이제 다시... 앱을 켜보겠다...!

근데 아래와 같은 에러가 발생!

Preparing expo-dev-launcher Pods/expo-dev-launcher » expo-dev-launcher-Info.plist
⚠️ Script has ambiguous dependencies causing it to run on every build.
To fix, go to: Xcode » onestep/onestep » Build Phases » 'Upload Debug Symbols to Sentry'
Either: Uncheck "Based on dependency analysis", or select output files to trigger the script
⚠️ Script has ambiguous dependencies causing it to run on every build.
To fix, go to: Xcode » onestep/onestep » Build Phases » '[CP-User][RNFB] Core Configuration'
Either: Uncheck "Based on dependency analysis", or select output files to trigger the script
⚠️ Script has ambiguous dependencies causing it to run on every build.
To fix, go to: Xcode » onestep/onestep » Build Phases » '[CP-User][RNFB] Crashlytics Configuration'
Either: Uncheck "Based on dependency analysis", or select output files to trigger the script

하라는대로... Xcode 열고 들어가서 based on dependency analysis 체크 해제해줌!
그랬더니 다른 에러가 발생!

error: Sandbox: bash(76582) deny(1) file-read-data /Users/(생략)/ios/Pods/Target Support Files/Pods-onestep/expo-configure-project.sh (in target 'onestep' from project 'onestep')

gpt에게 물어보니
expo-configure-project.sh 스크립트 파일에 접근할 수 없다는 메시지입니다. 이를 해결하기 위한 몇 가지 단계를 설명드리겠습니다:
1. 파일 접근 권한 확인

ls -l /Users/(생략)/ios/Pods/Target\ Support\ Files/Pods-onestep/expo-configure-project.sh

...
5. Xcode에서 권한 허용

Mac의 시스템 환경설정 > 보안 및 개인정보 보호 > 개인정보 보호 탭에서 터미널이나 Xcode의 디렉토리 접근 권한이 제대로 설정되어 있는지 확인하세요. 전체 디스크 접근 허용 또는 파일 및 폴더 권한에서 적절히 설정이 되어 있어야 합니다.

여러개 말해줬는데 위 두 개가 가능성 높아보이는 원인이라 두개 확인해보았지만 둘 다 진짜원인은 아니었다.

error: Sandbox: bash(85167) deny(1) file-read-data /Users/(생략)/ios/Pods/Target Support Files/Pods-onestep/expo-configure-project.sh (in target 'onestep' from project 'onestep')

여전히 같은 에러가 발생한다!
왜 file-read-data를 deny하는가

/Users/(생략)/ios/Pods/Target\ Support\ Files/Pods-onestep/expo-configure-project.sh

이 스크립트는 실행이 잘 되는지 확인해봤는데 잘된다

그래서 찾다보니 스택오버플로에서 같은 에러를 확인!
벨로그 글도 하나 발견!

따라해보니.....

문제해결!!

ios 앱 잘 열린다

이제 getToken했을 때 이전과같은 에러가 뜨지 않으면 된다!
과연 두구둥

잘된다!! 얏호
이제 알림 허용 거부해도 FCM 토큰 자체는 잘 받아와진다
공식문서에 ios setup 과정을 안보고 넘어간 난 바보

profile
안녕하세요, 반갑습니다.

0개의 댓글