일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 리액트네이티브 hooks
- 하우스플리퍼인테리어
- react native hook
- baseurl 오류
- unable to resolve module
- patch package
- hermes engine
- 안드로이드
- react native lodash
- Kotlin
- react
- tsconfig baseurl
- React Native
- 리액트네이티브 라이브러리 커스텀
- removeClippedSubviews
- 하우스플리퍼
- react native hooks
- onScrollToIndexFailed
- Android
- 리액트 네이티브 ios
- 라이브러리 커스텀
- 스팀게임추천
- Graveyard Keeper
- 헤르메스 엔진
- ReactNative
- privacy manifest
- 리액트 네이티브 헤르메스
- 리액트네이티브
- react native privacy manifest
- RecyclerView
Archives
- Today
- Total
숨참고 개발다이브
[React Native/Android] 포어그라운드(foreground)에서 푸시가 오지 않는 현상 - No channel id passed, notifications may not work. 본문
개발/React & React Native
[React Native/Android] 포어그라운드(foreground)에서 푸시가 오지 않는 현상 - No channel id passed, notifications may not work.
사라 Sarah 2022. 6. 10. 13:23728x90
No channel id passed, notifications may not work.
예전에 만들어둔 푸시 부분이 갑자기 포어그라운드에서 동작하지 않는 것을 확인했다.
처음에는 서버 오류인 줄 알고 서버를 확인해보았으나 정상 작동하였고, 경우의 수를 테스트해본 결과 포어그라운드의 문제였다.
안드로이드 오레오(API 26) 이상에서는 푸시 알림을 설정할 때 채널을 꼭 생성해주어야 하는데, 작업한 지 조금 된 프로젝트기도 하고 테스트 기기가 하필 저버전이어서 이 부분을 놓쳤다.
해결 방법)
앱 실행 시 createChannel을 통해 채널을 생성해주면 된다.
라이브러리는 react-native-push-notification을 사용하였다.
import PushNotification, {Importance} from 'react-native-push-notification';
...
PushNotification.createChannel(
{
channelId: "channel-id", // (required)
channelName: "My channel", // (required)
channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
playSound: false, // (optional) default: true
soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
importance: Importance.HIGH, // (optional) default: Importance.HIGH. Int value of the Android notification importance
vibrate: true, // (optional) default: true. Creates the default vibration pattern if true.
},
(created) => console.log(`createChannel returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
);
channelId와 channelName 만 필수값이므로 나머지 사항들은 설정할 부분만 추가로 넣어주면 된다.
이 코드를 앱이 시작하는 부분에 생성해주면 완료된다.
300x250
'개발 > React & React Native' 카테고리의 다른 글
Comments