add @notifee/react-native lib for push noti foreground
This commit is contained in:
parent
b29c7014ae
commit
a7128e69d9
26
App.js
26
App.js
@ -10,6 +10,7 @@ import React, { Component } from 'react'
|
|||||||
import { StatusBar, StyleSheet, Text, TouchableOpacity, Platform } from 'react-native'
|
import { StatusBar, StyleSheet, Text, TouchableOpacity, Platform } from 'react-native'
|
||||||
import MainNav from './src/navigation/MainNav'
|
import MainNav from './src/navigation/MainNav'
|
||||||
import messaging from "@react-native-firebase/messaging"
|
import messaging from "@react-native-firebase/messaging"
|
||||||
|
import notifee from '@notifee/react-native';
|
||||||
import { persistor, store } from './src/redux/store'
|
import { persistor, store } from './src/redux/store'
|
||||||
import { Provider } from 'react-redux'
|
import { Provider } from 'react-redux'
|
||||||
import { registerDevice } from './src/api/UserApi'
|
import { registerDevice } from './src/api/UserApi'
|
||||||
@ -60,6 +61,31 @@ class App extends Component {
|
|||||||
// Foreground message handler
|
// Foreground message handler
|
||||||
messaging().onMessage(async remoteMessage => {
|
messaging().onMessage(async remoteMessage => {
|
||||||
console.log('Foreground notification:', remoteMessage);
|
console.log('Foreground notification:', remoteMessage);
|
||||||
|
|
||||||
|
// Create a channel (required for Android)
|
||||||
|
const channelId = await notifee.createChannel({
|
||||||
|
id: 'default',
|
||||||
|
name: 'Default Channel',
|
||||||
|
});
|
||||||
|
|
||||||
|
// Display a notification
|
||||||
|
await notifee.displayNotification({
|
||||||
|
title: remoteMessage.notification?.title || 'New Notification',
|
||||||
|
body: remoteMessage.notification?.body || '',
|
||||||
|
android: {
|
||||||
|
channelId,
|
||||||
|
pressAction: {
|
||||||
|
id: 'default',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ios: {
|
||||||
|
foregroundPresentationOptions: {
|
||||||
|
banner: true,
|
||||||
|
badge: true,
|
||||||
|
sound: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Background/Quit message handler
|
// Background/Quit message handler
|
||||||
|
|||||||
@ -80,8 +80,15 @@
|
|||||||
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
||||||
willPresentNotification:(UNNotification *)notification
|
willPresentNotification:(UNNotification *)notification
|
||||||
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
|
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
|
||||||
|
|
||||||
|
// ถ้าเป็น Remote Notification (จาก FCM) ให้ซ่อนไว้ (None) เพื่อไม่ให้ซ้ำกับที่ Notifee จะแสดง
|
||||||
|
if ([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
|
||||||
|
completionHandler(UNNotificationPresentationOptionNone);
|
||||||
|
} else {
|
||||||
|
// ถ้าเป็น Local Notification (จาก Notifee) ให้แสดงผล (Alert/Sound/Badge)
|
||||||
completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound);
|
completionHandler(UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
|
||||||
didReceiveNotificationResponse:(UNNotificationResponse *)response
|
didReceiveNotificationResponse:(UNNotificationResponse *)response
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@invertase/react-native-apple-authentication": "^1.1.2",
|
"@invertase/react-native-apple-authentication": "^1.1.2",
|
||||||
|
"@notifee/react-native": "^9.1.8",
|
||||||
"@react-native-async-storage/async-storage": "^2.1.2",
|
"@react-native-async-storage/async-storage": "^2.1.2",
|
||||||
"@react-native-camera-roll/camera-roll": "^7.10.0",
|
"@react-native-camera-roll/camera-roll": "^7.10.0",
|
||||||
"@react-native-community/datetimepicker": "^3.0.2",
|
"@react-native-community/datetimepicker": "^3.0.2",
|
||||||
|
|||||||
@ -1500,6 +1500,11 @@
|
|||||||
"@nodelib/fs.scandir" "2.1.5"
|
"@nodelib/fs.scandir" "2.1.5"
|
||||||
fastq "^1.6.0"
|
fastq "^1.6.0"
|
||||||
|
|
||||||
|
"@notifee/react-native@^9.1.8":
|
||||||
|
version "9.1.8"
|
||||||
|
resolved "https://registry.yarnpkg.com/@notifee/react-native/-/react-native-9.1.8.tgz#3d55cb3fbcc21f9e35931e366afdf64b294da891"
|
||||||
|
integrity sha512-Az/dueoPerJsbbjRxu8a558wKY+gONUrfoy3Hs++5OqbeMsR0dYe6P+4oN6twrLFyzAhEA1tEoZRvQTFDRmvQg==
|
||||||
|
|
||||||
"@react-native-async-storage/async-storage@^1.13.4":
|
"@react-native-async-storage/async-storage@^1.13.4":
|
||||||
version "1.24.0"
|
version "1.24.0"
|
||||||
resolved "https://registry.yarnpkg.com/@react-native-async-storage/async-storage/-/async-storage-1.24.0.tgz#888efbc62a26f7d9464b32f4d3027b7f2771999b"
|
resolved "https://registry.yarnpkg.com/@react-native-async-storage/async-storage/-/async-storage-1.24.0.tgz#888efbc62a26f7d9464b32f4d3027b7f2771999b"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user