반응형

[ 푸시알림 완벽구현 - 최종판 ]

https://honeystorage.tistory.com/306

 

 

위 문제는 많은 개발자들이 겪고있는 이슈이다.

많은 해결법이 나와있지만 명쾌하지 못하다.

만든 개발자조차 얻어걸린 해결법을 해결법이랍시고

제공하는듯한 느낌을 지울 수 없다.

 

왜 푸시 진동이 안울려? 글에서도

언급한 서버 푸시 코드 수정을 통한 방법도 있지만,

이 또한 만능은 아니었다.

 

보다 완벽한 푸시 처리를 위해

local-notification으로 알림으 띄우는 코드를

setBackgroundMessageHandler의 리스너로 등록한뒤

빌드해서 테스트를 해보았다.

 

왜냐면 시뮬레이터에서는

애초에 푸시알림이 지원되지않아

부정확한 테스트밖에 할수없다고 판단되었기 때문이다.

 

 

(공식 가이드의 지시에 따라 isHeadless의 경우 null 대신 임의의 컴포넌트를 리턴함)

// app.js 메시지 수신 설정
function HeadlessCheck({isHeadless}) {
  const queryClient = new QueryClient();

  if (isHeadless) {
    // App has been launched in the background by iOS, ignore
    return <SafeAreaView style={{flex: 1, backgroundColor: '#ffffff'}}></SafeAreaView>;
  }

  return (
    <QueryClientProvider client={queryClient}>
      <Provider store={store}>
        <App />
      </Provider>
    </QueryClientProvider>
  );
}

messaging().setBackgroundMessageHandler(onMessageReceived);
function onMessageReceived(message) {
  localNoti.fire({
    title: '알림 수신',
    message: '백그라운드 알림 수신 성공!!'
  })
}

AppRegistry.registerComponent(appName, () => HeadlessCheck);

# localNoti는 @react-native-community/push-noitification-ios 와

react-native-push-notification으로 만든 클래스 인스턴스이다.

 

 

테스트 결과

setBackgroundMessageHandler는 여전히 멍청이였다.

 

원인은 생각보다 더 멍청한 나에게 있었다.

프로젝트내에

setBackgroundMessageHandler 리스너가 2개가 있었고

다른 한곳에 등록된 setBackgroundMessageHandler가

동작중이었던 것이다.

 

따라서, 위 설정에 따라 셋업했다면

설정상에 문제는 없는거로!

 

 

[ 푸시알림 완벽구현 - 최종판 ]

https://honeystorage.tistory.com/306

 

 

[ 참고 ]

https://github.com/invertase/react-native-firebase/issues/5656

 

messaging.setBackgroundMessageHandler: How to invoke when app is in quit state on iOS · Issue #5656 · invertase/react-native-f

Documentation Feedback This is a solution for invoking messaging().setBackgroundMessageHandler() when the app is in quit state on iOS. In the past couple of days, I have gone through a ton of issue...

github.com

 

https://rnfirebase.io/faqs-and-tips#on-ios-when-the-app-is-in-quit-state-the-setbackgroundmessagehandler-is-never-invoked-even-when-i-receive-the-notification-how-can-i-fix-this

 

FAQs and Tips | React Native Firebase

Copyright © 2017-2020 Invertase Limited. Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the Apache 2.0 License. Some partial documentation, under the

rnfirebase.io

 

https://notifee.app/react-native/docs/installation

 

Installation | Notifee

Quick start guide for installing and running on React Native. The Notifee core library is packaged an Android "AAR" file. It is distributed in a "local maven repository" for Android integration. You must add this repository to your android/build.gradle bui

notifee.app

 

 

 

반응형
반응형

[ 푸시알림 완벽구현 - 최종판 ]

https://honeystorage.tistory.com/306

 

 

@react-native-firebase/app

@react-native-firebase/messaging

 

두개 모듈을 이용해 푸시알림을 구현했다.

ios & android 모두 잘 동작하는 듯 했으나 아니었다

 

Docs를 보다보면 푸시알림 수신관련해

상태를 구분해둔 표가있다.

 

그렇다는건

우리도 상태별로 테스트를

진행해서 문제가 없는지 확인해야된다는 것이다.

 

나는 이 중

Android 디바이스의 앱이 Quit Stats 상태일때

정상적으로 알림을 띄우지 못했다.

 

1박2일간의 사투끝에 어이없는 실수가 있었음을 깨달았다.

문제 해결 과정이 핵심이다.

 

1. Google에 문제 상황 검색하기

- 검색어 예시 : react-native-firebase push notification not working on android in quit stats

- 검색어 예시 : - rnfb not working in quit stats

 

2. git에 예시코드 찾아보기

- 검색어 예시 : react-native-firebase v6

- 검색어 예시 : rn firebase

 

3. 잠시 멈추어, 정확히 어느상황에 안되는지 확인

- 생각을 정리해보니 JS단까지 알림이 전달되않음.

- Java에는 알림이 전달이 되는지 확인해볼 필요가 있음

 

4. 디바이스를 연결하고 Android Studio로 디버깅

- 디바이스 연결

- Android Studio 실행

- react-native run-android

- Android Studio 하단의 LogCat [info]를 모니터링

- 서버에서 알림 발송

- Java에는 요청이 정확히 오지만 에러가 났음을 발견

- 에러메시지 >>> SoLoader.init ....

- MainApplication.java에 해당 코드를 주석처리 해뒀던것이 기억남

- 주석해제

 

5. 푸시알림 전송 및 이슈해결 확인

 

 

결론

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false); // <-- 주석해제했음
  }

 

 

>>> RNFirebase 왜 아이콘이 안나와?

>>> RNFirebase 왜 진동이 안울려?

 

 

[ 푸시알림 완벽구현 - 최종판 ]

https://honeystorage.tistory.com/306

반응형