I am using react-native 0.60, Firebase push notification. I need help with react native firebase ios push notification with data payload. I am able to send notifications with data payload. I am able to receive the notification when the app is foreground, background, killed. I am sending data with notification.
{
"to" : "FCM Token",
"show_in_foreground" : "true",
"collapse_key" : "type_a",
"notification" : {
"notification_type" : "N",
"ad_type" : "banner",
"sub_type" : "info",
"text_message" : "Lorem ipsum dolor sit amet",
"Title": "Notification 0000",
"image_url": "https://firebasestorage.com/xyz",
"ad_time" : 7,
"x_time" : 4,
"delay_time" : 4
},
"data" : {
"notification_type" : "N",
"ad_type" : "banner",
"sub_type" : "info",
"text_message" : "Lorem ipsum dolor sit amet",
"Title": "Notification 0000",
"image_url": "https://firebasestorage.googleapis.com/xyz",
"ad_time" : 7,
"x_time" : 4,
"delay_time" : 4
},
"content-available" : true,
"priority": "high"
}
I want to show notification and also store data in local app database at the same time even if the user doesn't click on the notification.
I am able to handle the notification when user clicks on the notification. I want to update the data in the app when the notification is received by the user and also show the notification. I dont want to use silent background notification.
My Appdelegate code
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{
if ([[FIRAuth auth] canHandleNotification:userInfo]) {
completionHandler(UIBackgroundFetchResultNoData);
return;
}
[[FIRMessaging messaging] appDidReceiveMessage:userInfo];
[[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
NSLog(@"Inactive - the user has tapped in the notification when app was closed or in background 3");
}
I want to achieve 1. User should get the notification even if the app is closed, killed, background. 2. User's App local Database should be updated even if user doesnt click on the notification.
I have achieved the first point looking for 2nd. I am new to react native. I know that when the notification is received the completion handler method is called. when the app is killed nothing is showed in the xcode log. how do i write code in completion handler method ? and how do i check if the method is called and task is performed.