Solve Problem/React Native
[React Native] push notification custom sound 설정하기 / 커스텀 사운드 / 푸시알람
안다희
2020. 9. 28. 17:27
728x90
[React Native] push notification custom sound 설정하기 / 커스텀 사운드 / 푸시알람
라이브러리: github.com/zo0r/react-native-push-notification
버전: 5.1.0
1. iOS
1) project/ios 폴더에 .caf 파일을 추가한다. (xcode에서 말고 finder에서!)
2) xcode에서 다음과 같이 프로젝트 이름에서 우클릭 - Add Files to "project" 클릭 후 ios 폴더에 추가해놓은 파일을 선택한다.
3) 코드 작성
import PushNotification, { PushNotificationScheduleObject } from 'react-native-push-notification';
const scheduleObj: PushNotificationScheduleObject = {
id: "1",
date: new Date(),
vibrate: true,
ongoing: false,
priority: 'max',
visibility: 'public',
importance: 'max',
allowWhileIdle: true,
title: "title",
message: "message",
playSound: true,
soundName: "default_alarm_sound.caf",
}
PushNotification.localNotificationSchedule(scheduleObj);
soundName에 꼭 확장자까지 써줘야 한다.
2. Android
1) project/android/app/src/main/res/raw에 추가할 파일을 넣는다.
2) 코드 작성
import PushNotification, { PushNotificationScheduleObject } from 'react-native-push-notification';
const scheduleObj: PushNotificationScheduleObject = {
id: "1",
date: new Date(),
vibrate: true,
ongoing: false,
priority: 'max',
visibility: 'public',
importance: 'max',
allowWhileIdle: true,
title: "title",
message: "message",
playSound: true,
soundName: "default_alarm_sound",
}
PushNotification.localNotificationSchedule(scheduleObj);
여기 주의할 점은 ios와는 달리 확장자를 적어주지 않는다는 것이다.
-> 이렇게 하면 두 플랫폼에 모두 커스텀 사운드를 적용할 수 있다!