rn) firebase cloud messaging 이미지

kiten Jung·2023년 7월 3일
0

react-native

목록 보기
2/2
post-thumbnail

파이어베이스 fcm 및 cloud messaging 설치가 기본적으로 되어 있다고 가정으로 시작하겠습니다

push messaging에서 이미지를 추가하기 위해서 안드로이드는 별다른 설정할게 없습니다. 반대로 ios는 이미지를 나태내게 하기 위해서 별도의 설정을 추가해 주어야 합니다.

firebase ios 이미지 설정 공식문서
https://rnfirebase.io/messaging/ios-notification-images

  • 파이어 베이스 설명 가져옴
  1. file - new - targer - notification service extension 추가

  2. podfile에 타겟 추가

target 'ImageNotification' do
  pod 'Firebase/Messaging', '~> VERSION_NUMBER' # eg 6.31.0
end

VERSION_NUMBER는 파이어베이스 홈페이지에 가셔서 배포된 버전을 찾으시면 됩니다.(글쓴 시점은 10.5.0입니다.)
버전을 적으시고 pod install을 합니다.(에러 발생시 에러처리 하셔야 합니다.)

  1. 타겟에 라이브러리 추가

    추가한 타겟 폴더에 모듈 파일로 가서 헤더 및 내용 수정을 합니다.
#import "NotificationService.h"
+ #import "FirebaseMessaging.h"
- // Modify the notification content here...
- self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];
- self.contentHandler(self.bestAttemptContent);
//위 2줄 제거
//아래 1줄 추가
+ [[FIRMessaging extensionHelper] populateNotificationContent:self.bestAttemptContent withContentHandler:contentHandler];

이렇게 하면 ios에서도 인스타에 태그를 하면 이미지와 글이 나오는거 처럼 잘 나오는 것을 확인할 수 있습니다.

테스트는 Firebase홈페이지에서 프로젝트-클라우드메시징-알림작성에서 fcm토큰을 가지고 있을시 테스트 메세지를 보낼 수 있습니다.

pod install시 마주한 에러

  1. 'sharedApplication' is unavailable: not available on iOS (App Extension)

post_install do |installer|
    react_native_post_install(installer)

    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
        end
      end
  end

shard가 에러가 발생하여 APPLICATION_EXTENSION_API_ONLY 'No'를 추가

profile
느림느림

0개의 댓글