-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
✨Feature - FCM Notification 기능 추가 (#59)
- Loading branch information
Showing
10 changed files
with
113 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {NavigationProp} from '@react-navigation/native'; | ||
import PushNotificationIOS, { | ||
PushNotification, | ||
} from '@react-native-community/push-notification-ios'; | ||
import messaging from '@react-native-firebase/messaging'; | ||
|
||
export const initFirebaseNotification = ( | ||
navigation: NavigationProp<ReactNavigation.RootParamList>, | ||
) => { | ||
// 푸시 메세지 Notification 처리 | ||
messaging().onMessage(async remoteMessage => { | ||
console.log('Message handled in the foreground!', remoteMessage); | ||
if (remoteMessage.data) { | ||
PushNotificationIOS.addNotificationRequest({ | ||
id: 'remoteMessage', // unique identifier for the notification | ||
title: remoteMessage.notification?.title || 'Default Title', | ||
body: remoteMessage.notification?.body || 'Default Body', | ||
userInfo: remoteMessage.data, | ||
}); | ||
} | ||
}); | ||
|
||
// 백그라운드에서 Notification 눌렀을 때 이벤트 처리 | ||
messaging().onNotificationOpenedApp(remoteMessage => { | ||
try { | ||
console.log('Message handled in the background!', remoteMessage); | ||
const popupId = remoteMessage?.data?.popupId; | ||
// @ts-ignore | ||
navigation.navigate('PopUpDetail', {id: popupId}); | ||
} catch (error) { | ||
console.log('Background Notification Error', error); | ||
} | ||
}); | ||
|
||
// 포그라운드에서 Notification 눌렀을 때 이벤트 처리 | ||
PushNotificationIOS.addEventListener( | ||
'localNotification', | ||
(notification: PushNotification) => { | ||
try { | ||
const pushData = notification.getData(); | ||
// @ts-ignore | ||
navigation.navigate('PopUpDetail', {id: pushData.popupId}); | ||
} catch (error) { | ||
console.log('Foreground Notification Error', error); | ||
} | ||
}, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import PublicApiInstance from '../apiInstance/PublicApiInstance.ts'; | ||
|
||
interface PushTokenParams { | ||
token: string; | ||
device: string; | ||
} | ||
export const registerPushToken = async (params: PushTokenParams) => { | ||
const response = await PublicApiInstance.post( | ||
'/api/v1/noti/apply/FCMtoken', | ||
params, | ||
); | ||
return response.data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters