@@ -84,6 +84,16 @@ export const App = () => {
8484 } ) ;
8585 } ;
8686
87+ const sendSilentNotification = ( ) => {
88+ DeviceEventEmitter . emit ( 'remoteNotificationReceived' , {
89+ remote : true ,
90+ aps : {
91+ category : 'REACT_NATIVE' ,
92+ 'content-available' : 1 ,
93+ }
94+ } ) ;
95+ } ;
96+
8797 const sendLocalNotification = ( ) => {
8898 PushNotificationIOS . presentLocalNotification ( {
8999 alertTitle : 'Sample Title' ,
@@ -122,27 +132,42 @@ export const App = () => {
122132 } ;
123133
124134 const onRemoteNotification = ( notification ) => {
135+ const isClicked = notification . getData ( ) . userInteraction === 1
136+
125137 const result = `
126138 Title: ${ notification . getTitle ( ) } ;\n
127139 Message: ${ notification . getMessage ( ) } ;\n
128140 badge: ${ notification . getBadgeCount ( ) } ;\n
129141 sound: ${ notification . getSound ( ) } ;\n
130142 category: ${ notification . getCategory ( ) } ;\n
131- content-available: ${ notification . getContentAvailable ( ) } .` ;
143+ content-available: ${ notification . getContentAvailable ( ) } ;\n
144+ Notification is clicked: ${ String ( isClicked ) } .` ;
132145
133- Alert . alert ( 'Push Notification Received' , result , [
134- {
135- text : 'Dismiss' ,
136- onPress : null ,
137- } ,
138- ] ) ;
146+ if ( notification . getTitle ( ) == undefined ) {
147+ Alert . alert ( 'Silent push notification Received' , result , [
148+ {
149+ text : 'Send local push' ,
150+ onPress : sendLocalNotification ,
151+ } ,
152+ ] ) ;
153+ } else {
154+ Alert . alert ( 'Push Notification Received' , result , [
155+ {
156+ text : 'Dismiss' ,
157+ onPress : null ,
158+ } ,
159+ ] ) ;
160+ }
139161 } ;
140162
141163 const onLocalNotification = ( notification ) = > {
164+ const isClicked = notification . getData ( ) . userInteraction === 1
165+
142166 Alert . alert (
143167 'Local Notification Received' ,
144168 `Alert title: ${ notification . getTitle ( ) } ,
145- 'Alert message: ${ notification . getMessage ( ) } ` ,
169+ 'Alert message: ${ notification . getMessage ( ) } ,
170+ Notification is clicked: ${ String ( isClicked ) } .` ,
146171 [
147172 {
148173 text : 'Dismiss' ,
@@ -171,6 +196,8 @@ export const App = () => {
171196 label = "Schedule fake local notification"
172197 />
173198
199+ < Button onPress = { sendSilentNotification } label = "Send fake silent notification" />
200+
174201 < Button
175202 onPress = { ( ) => PushNotificationIOS . setApplicationIconBadgeNumber ( 42 ) }
176203 label = "Set app's icon badge to 42"
0 commit comments