0

I have this problem now, I need to handle the info of push notification when app in backround, I mean, even not tap the notifcation. That mean this application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler must be called in background ! Here is my code for it

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{

    NSLog(@"full message %@", userInfo);
    NSDictionary *aps = [userInfo objectForKey:@"aps"];
    NSLog(@"full aps %@", aps);
    NSString *custom = [userInfo objectForKey:@"custom"];
    NSLog(@"full custom %@",custom);
    completionHandler(UIBackgroundFetchResultNewData);
    [[NSNotificationCenter defaultCenter] postNotificationName:@"notificationRemote" object:nil userInfo:userInfo];
}

I really need handle the info, such that save it to local everytime I have any notification, no matter I tap in push notification.

I search and I saw that I need content-available for my payload, but I can't find it in Firebase Console Notification.

KENdi
  • 7,576
  • 2
  • 16
  • 31
Thanh Hải
  • 243
  • 1
  • 3
  • 10
  • hi , i have a similar scenario but slightly modification required , like when i get the push notification ,the app should get active in background and do the task given in , ( like user's location update code ) ,- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo , but my app would not get active until user taps on the notification . so , how would i get this done while app is in background ? dose anyone know the solution for this ? – Moxarth Nov 28 '17 at 05:51
  • @Moxarth Have you found solution for this? – Beu May 30 '20 at 05:46

2 Answers2

1

Yup, you need content-available key in payload for silent push notification.

for more about FCM, U can see this link: Firebase silent apns notification

Community
  • 1
  • 1
0

You can use FireBase Cloud Function to create a payload and Fire a Notification.You can handle events in the Firebase Realtime Database. The Realtime Database supports the onWrite() event, which triggers anytime data is created, destroyed, or changed in a specified database location. Please refer this tutorial for detail which may help you https://code.tutsplus.com/tutorials/serverless-apps-with-firebase-cloud-functions--cms-28557

Nishant Bhindi
  • 2,242
  • 8
  • 21
  • but i cant do with firebase console ? – Thanh Hải May 22 '17 at 13:21
  • you need to write the cloud function locally in Node.js and deploy that with firebase.please see the sample code on https://github.com/firebase/functions-samples/blob/master/fcm-notifications/functions/index.js – Nishant Bhindi May 22 '17 at 13:28