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와는 달리 확장자를 적어주지 않는다는 것이다.
-> 이렇게 하면 두 플랫폼에 모두 커스텀 사운드를 적용할 수 있다!
'Solve Problem > React Native' 카테고리의 다른 글
[React Native] naver login / 네이버 로그인 (0) | 2020.10.06 |
---|---|
[React Native] Facebook SDK 적용하기 (0) | 2020.09.30 |
[React Native] Custom Font 적용 (Google Fonts) (0) | 2020.09.12 |
[React Native] Sentry로 로그 이벤트 확인하기 (1) | 2020.09.01 |
[React Native] Firebase Admob - Rewards 보상형 동영상 광고 띄우기 (6) | 2020.08.29 |