cordova push2 상세
- 통돌이
- 2022. 7. 6.
1. 클라이언트 js코드 - (document ready일 경우에 호출될 수 있도록 하기)
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
// Cordova is now initialized. Have fun!
console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
document.getElementById('deviceready').classList.add('ready');
const push = PushNotification.init({
android: {
},
browser: {
pushServiceURL: 'http://push.api.phonegap.com/v1/push'
},
ios: {
alert: "true",
badge: "true",
sound: "true"
},
windows: {}
});
push.on('registration', (data) => {
console.log(JSON.stringify(data));
console.log(data.registrationId);
//
});
push.on('notification', (data) => {
console.log(JSON.stringify(data));
// data.message,
// data.title,
// data.count,
// data.sound,
// data.image,
// data.additionalData
});
push.on('error', (e) => {
// e.message
});
}
2. foreground상태에서도 notification 알림 보이게
2-1. 코드 위치 (코틀린) - /app/java/FCMService
2-2. 코드 추가 -
showNotificationIfPossible(extras)
3. 1차 테스트 (파이어베이스 - 발송딜레이가 있음)
파이어베이스 -> 해당 프로젝트 (패키지명 중요) -> 참여 -> 매시징 -> 새캠페인 (or 처음 보내면 first message 인가 뜰꺼임) -> 입력할꺼 입력하고 발송 -> 5분내로 푸시 도착(바로 안날라옴)
4. 2차 테스트 (포스트맨 - 즉시발송)
- Headers
Content-Type : application/json
Authorization : key=FCM_KEY
- Body
{
"notification": {
"title": "테스트",
"body": "입니다."
},
"to":"푸시 레지스트 아이디",
"priority":"high",
"data":{
"urlLink":"TEST"
}
}
4. 다음번에는 서버에 푸시 발송코드를 만들어보자
참고자료
https://github.com/havesource/cordova-plugin-push/blob/master/docs/API.md
'통돌이' 카테고리의 다른 글
php 이미지 데이터 로그 수집 (0) | 2022.07.29 |
---|---|
cordvoa ios 이미지 확장 (0) | 2022.07.19 |
cordova push1 초기 (0) | 2022.07.06 |
안드로이드 dpi 계산 (0) | 2022.07.01 |
공자 -논어 폐단이 되는 여섯가지 (0) | 2020.02.05 |