@@ -5,6 +5,7 @@ import { Notifications, type Registered } from 'react-native-notifications';
55
66export default function App ( ) {
77 const [ link , setLink ] = React . useState < string | undefined > ( ) ;
8+ const [ token , setToken ] = React . useState < string | undefined > ( ) ;
89
910 React . useEffect ( ( ) => {
1011 // If using Deferred Deep Linking, make sure to enable the app install event
@@ -22,17 +23,15 @@ export default function App() {
2223 Notifications . events ( ) . registerRemoteNotificationsRegistered (
2324 ( event : Registered ) => {
2425 console . log ( event . deviceToken ) ;
26+ setToken ( event . deviceToken ) ;
2527 }
2628 ) ;
2729
2830 // Handle notifications received in foreground
2931 const foregroundSubscription =
3032 Notifications . events ( ) . registerNotificationReceivedForeground (
31- ( notification , completion ) => {
32- console . log (
33- `Notification received in foreground: ${ notification . title } : ${ notification . body } `
34- ) ;
35- completion ( { alert : false , sound : false , badge : false } ) ;
33+ ( _notification , completion ) => {
34+ completion ( { alert : true , sound : true , badge : false } ) ;
3635 }
3736 ) ;
3837
@@ -51,6 +50,20 @@ export default function App() {
5150 }
5251 ) ;
5352
53+ Notifications . getInitialNotification ( )
54+ . then ( ( notification ) => {
55+ if ( notification ) {
56+ console . log ( 'App opened from notification:' ) ;
57+ console . log ( `${ JSON . stringify ( notification , null , 2 ) } ` ) ;
58+
59+ // Handle the notification with MovableInk
60+ RNMovableInk . handlePushNotificationOpenedWithContent (
61+ notification . payload
62+ ) ;
63+ }
64+ } )
65+ . catch ( ( err ) => console . error ( 'getInitialNotification() failed' , err ) ) ;
66+
5467 // Get the deep link used to open the app
5568 const getInitialURL = async ( ) => {
5669 const universalLink = await Linking . getInitialURL ( ) ;
@@ -97,6 +110,10 @@ export default function App() {
97110 return (
98111 < View style = { styles . container } >
99112 < Text > Resolved Link: { link } </ Text >
113+ < Text >
114+ Device Token: { '\n' }
115+ { token }
116+ </ Text >
100117
101118 < Button
102119 title = "Test Product Searched"
@@ -176,6 +193,8 @@ const styles = StyleSheet.create({
176193 flex : 1 ,
177194 alignItems : 'center' ,
178195 justifyContent : 'center' ,
196+ gap : 16 ,
197+ padding : 20 ,
179198 } ,
180199 box : {
181200 width : 60 ,
0 commit comments