Francesco Destino
Francesco Destino

Reputation: 349

Push notifications on Swift

I have a really big problem with Firebase Notifications; my problem is that i can receive notification in background mode and foreground mode, but if I terminate it(kill it from the ram) I can't receive anything.

I found that if I comment this function

func application(_ application: UIApplication,
                 didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Messaging.messaging().apnsToken = deviceToken
}

I can receive a notification when i reopen the application after it's terminated, but i can't get a notification in background like before.

There's any way to solve it, because my application should receive notification everytime: background, foreground and when application is reopened from a terminated state

The following is an example of my notification's JSON:

{
"content_available": true,
"priority": "high",
"data": {
    "priority": "SILENT",
    "target": "contact",
    "msgBody": "",
    "msgTitle": ""
},
"to": "firebase_TOKEN"

}

I also want to say that this notification should be silent

Upvotes: 1

Views: 99

Answers (2)

Dharmesh Kheni
Dharmesh Kheni

Reputation: 71852

When app is killed notification will be handled from operating system so it needs some specific key to display notification.

Like consider the below example:

{

"content_available": true, 
  "notification": {
    "title":  "has sent you a message", 
    "sound": "default", 
    "body": "Hi", 
    "badge": 6

  }, 
  "to": "firebase_TOKEN", 
  "priority": "high"
}

Here you need to replace "data" with "notification" and you also need a "title" instead of "msgTitle" and "msgBody" will be replaced with "body".

Looks like your's is a android payload which won't work with iOS.

Upvotes: 2

Ashish P
Ashish P

Reputation: 3056

You must required to add "Content-available" : "1", in your notification to get push notification when application killed.

Upvotes: 2

Related Questions