해결된 질문
작성
·
187
0
PushNotification.localNotification 이 포그라운드 일떄
안드로이드에서 백그라운드 때처럼 알림동작을 하지 않습니다.
메니페스트는 잘 추가한 상태입니다.
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground"
android:value="true"/>
.....
onNotification: function (notification: any) {
if (notification.channelId === 'riders') {
console.log('NOTIFICATION riders:', notification);
if (notification.message || notification.data.message) {
const title = notification.title || notification.data.title;
const message = notification.message || notification.data.message;
//Alert.alert(title, message, [{text: '확인'}]);
if (notification.foreground) {
PushNotification.localNotification({
channelId: 'riders',
autoCancel: true,
title: 'title',
message: 'message',
invokeApp: true,
});
}
}
}
notification.finish(PushNotificationIOS.FetchResult.NoData);
}
.....
onNotification
이 펑션은 잘 물고 들어옵니다.
console.log('NOTIFICATION:', notification);
로그도 잘 찍히구요.
하지만 이 안에서 선언한
PushNotification.localNotification
펑션이 전혀 반응이 없습니다.
가이드를 정독해도 제가 놓친 부분이 없네요...
포그라운드일때도 백그라운드일때처럼 알림이 오길 원해서 추가한 코드인데 되지를 않네요 ...
혹시 이에대해서 해답을 아시면 공유 부탁드립니다. ㅜ
답변 2
0
소중한 답변 감사합니다.
원인은 정말 바보같게도 다른 곳에 있었으며 안드로이드를 아직 잘 이해하지 못한 저에게 있었습니다.
....
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
....
intent-filter 에 메인, 런처 가 포함한 곳에 다 같이 넣어버리면 앱아이콘이 사라지는 이슈가 있었습니다.
제가 직면했던 문제였고 이 이슈를 해결하니까 포그라운드 알림도 동작하기 시작했습니다.
수정된 코드는 다음과 같습니다.
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
다음과 같이 인텐트 필터를 메인과 뷰를 분리해서 등록해야합니다.
0