0
votes

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.

2
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
@Moxarth Have you found solution for this?Beu

2 Answers

1
votes

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

0
votes

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