Gianluca
Gianluca

Reputation: 143

Push notifications don't work when app is in background

There's a problem with my app and I don't know why: notification with Firebase doesn't work when the app is in the background, but they are fired once the app goes in the foreground. The problem is not how to handle them, but why when the app is in foreground notification popup are fired, but when are in the background not.

{ 
 "notification" : {
  "title" : "...",
  "body" : "...",
  "icon" : "...",
  "sound" : "default"
},
"to": "...",
  "priority" : "high",
"data" : {
   ...
}
}

This is a sample of the notification I tried to fire with the postman. Any ideas? Thanks

Upvotes: 0

Views: 440

Answers (2)

JeeVan TiWari
JeeVan TiWari

Reputation: 335

Check in capabilities You turned on Remote Notification in Background Modes.

Upvotes: 0

Nirmalsinh Rathod
Nirmalsinh Rathod

Reputation: 5186

1) Check your certificate and bundle identifier in Firebase.

2) Make sure you send Device Token to Firebase.

- (void)application:(UIApplication *)application
   didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

// For Development
    [FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeSandbox];

// For Production
    [FIRInstanceID instanceID] setAPNSToken:deviceToken type: FIRInstanceIDAPNSTokenTypeProd];

    }

You can checkout this Link for more information.

Upvotes: 2

Related Questions