본문 바로가기
front-end/React Native

[RN]react-native-push-notification 커스텀사운드 적용하기(안드로이드)

by -제이리 2023. 3. 15.
728x90
320x100

[문제상황]

react-native-push-notification라이브러리를 사용하면서 push알림의 커스텀사운드가 적용이 잘 안되어 애를 먹고 있었다.

분명 경로 설정도 잘 되었고 soundName에도 맞게 잘 설정을 했는데 안되는 이유가 답답했다.

 

https://github.com/zo0r/react-native-push-notification/issues/2050

 

이슈를 탐색하던중 위와 같은 답변을 보았고 드디어 궁금증이 해결되었다.

 

즉 채널을 한번 생성하게 되면 지정된 사운드는 수정이 불가능하다는 소리다.  

 

나는 이제껏 PushNotification.localNotificationSchedule()안에서만 soundName을 설정하고 있었고 이미 채널을 생성할때는 default사운드가 설정되어있기 때문에 수정이 안되었던 것이다..

 

[해결방법]

PushNotification.createChannel()에서 soundName을 지정해주어야 한다.

PushNotification.localNotificationSchedule()에서 설정한다 한들 커스텀사운드가 제대로 나오질 않는다.

 

(예시코드)

// 채널생성
PushNotification.createChannel(
    {
      channelId: 'channel-id', 
      channelName: 'Channel Name',
      soundName: '커스텀사운드.mp3', // -> 꼭 채널생성할때 설정해주어야 한다.
      importance: 4, 
      vibrate: true,
    },
    created => console.log(`Channel ${created ? '' : 'not '}created`),
  );
  
  
// 로컬알람 설정
PushNotification.localNotificationSchedule({
      channelId: 'channel-id',
      title: '제목',
      message: '메세지',
      date: new Date(Date.now() + 5 * 1000),
    });
728x90
320x100

댓글