Firebase iOS notifications not received on device - ios

We have two kind of firebase notifications, one with the notification field and one without (this field it's used by the system to display the banner).
The one with is always received, the one without is received for a certain row of attempts and then stops being received.
These are the payloads:
The one always being received:
{
"content_available": true,
"data": {
"pushCategory": "ALEXA",
"body": "body",
"message": "message",
"title": "status/update",
"updateStatus": {
"operationId": "7fc0e1ff-cc0d-4045-8b30-69710bf80c24",
"status": 0,
"action": "makecoffee",
"description": "",
"stock": {
"remaining": "91",
"threshold": "10",
"depletion": false
}
}
},
"notification": {
"title": "title",
"body": "body msg"
},
"apns": {
"headers": {
"apns-priority": "10"
}
},
"to": "----"
}
The one not being received randomly:
{
"content_available": true,
"data": {
"pushCategory": "ALEXA",
"body": "body",
"message": "message",
"title": "status/update",
"updateStatus": {
"operationId": "7fc0e1ff-cc0d-4045-8b30-69710bf80c24",
"status": 0,
"action": "makecoffee",
"description": "",
"stock": {
"remaining": "91",
"threshold": "10",
"depletion": false
}
}
},
"apns": {
"headers": {
"apns-priority": "10"
}
},
"to": "----"
}
The equivalent notification using directly the APNS servers and without the alert field is always received. (the alert field is the one that tells the system to display the banner)
I contacted the Firebase support but the issue in ongoing, do you know what could be the issue?

I've never used Firebase.
I'm not sure if apns-priority in your payload has an effect. I just don't know:
"apns": {
"headers": {
"apns-priority": "10"
}
},
I think you have to get rid of it and just use priority field itself. Let Firebase map the fields itself...
From Firebase docs, look for the description of the priority parameter and how it behaves differently for data vs notification :
Sets the priority of the message. Valid values are "normal" and
"high." On iOS, these correspond to APNs priorities 5 and 10.
By default, notification messages are sent with high priority, and
data messages are sent with normal priority. Normal priority optimizes
the client app's battery consumption and should be used unless
immediate delivery is required. For messages with normal priority, the
app may receive the message with unspecified delay.
When a message is sent with high priority, it is sent immediately, and
the app can display a notification.
The payload with data ends up ultimately with a firebase priority of "normal" which translates to apns-priority 5
For notification the firebase priority of "high" translates to apns-priority of 10
For more on apns-priority, see apns-docs
The priority of the notification. If you omit this header, APNs sets
the notification priority to 10.
Specify 10 to send the notification immediately.
Specify 5 to send the notification based on power considerations on
the user’s device.

Related

Notification service extension not come to device with api.sandbox.push.apple.com

I have an issue with Notification Service Extension on iOS 13. This issue is not always happen.
When I push a notification with mutable-content = 1, on development apple server ( api.sandbox.push.apple.com:443), Apple return success on my server, but no notification comes to my device. Sometimes it still comes, but very late, for example I push it at 9:00 AM, it comes to my device at 9:15 AM, and show exactly time (15 mins ago).
Is this an apple error or my error? If it's my error, how do I fix this? And if it's Apple's error, does it happen on real server (api.push.apple.com:443)?
Thanks!
"Mutable-content" should be inside "aps" dictionary
Try this if you are sending from apns server
{
"aps": {
"category": "content_added_notification",
"alert": {
"title": "Photos",
"body": "Antoine added something new - take a look"
},
"mutable-content": 1
},
"image_url": "https://www.example.com/image_url"
}
And this if you are sending from firebase
let dict = ["to": "SERVER-KEY",
"notification":["body":"body text",
"title":"notification text",
"category": "myNotificationCategory",
"mutable-content": true],
"data":[
"mediaUrl": "https://homepages.cae.wisc.edu/~ece533/images/airplane.png"
]]as [String:Any]

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
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.
You must required to add "Content-available" : "1", in your notification to get push notification when application killed.

Include APS payload data in local notification to watchOS

I'm trying to display a custom Long-Look UI when receiving a local notification on my watch extension.
I tested this sample .apns payload:
{
"aps": {
"alert": {
"body": "Test message",
"title": "Optional title"
},
"category": "myCategory",
"thread-id":"5280"
},
"WatchKit Simulator Actions": [
{
"title": "First Button",
"identifier": "firstButtonAction"
}
],
"customKey": "Use this file to define a testing payload for your notifications. The aps dictionary specifies the category, alert text and title. The WatchKit Simulator Actions array can provide info for one or more action buttons in addition to the standard Dismiss button. Any other top level keys are custom payload. If you have multiple such JSON files in your project, you'll be able to select them when choosing to debug the notification interface of your Watch App."
}
and it works fine. I also have a dynamic notification scene designed on the storyboard.
I'm scheduling local notifications from the iOS side like this (and lock the phone right afterward to force the notification to go on my watch)
let content = UNMutableNotificationContent()
content.title = "Early bird"
content.categoryIdentifier = "myCategory"
content.userInfo = [
"userData": [
"WatchKit Simulator Actions": [
[
"title": "Button 1",
"identifier": "button1Action",
],
[
"title": "Button 2",
"identifier": "button2Action",
]
]
]
]
I think I'm setting my userInfo wrong. How do I set the correct payload so my watchOS extension can render the long-look correctly?

Handling Push Notification on Lock Screen ios

In my application Push notification receives data in json format
Which is this
aps = {
alert = "{\"messsage\":\"what to do when boarded \",\"chatBox\":\"130701.130693\",\"sender_id\":\"130701\",\"sender_name\":\"reg41\",\"sender_image_url\":\"http:\\/\\/www.playmit.com\\/images\\/user_profile_images\\/\",\"receiver_id\":\"130693\",\"type\":\"chat\"}";
};
}
But also on lock screen when app is not running or app is in background when push notification received it shows same json contents in push notification
So how do I handle this.
Thanks.
In the image Quizmatch receives push notification in json format
You are not allowed to put custom tags inside aps tag. Here's what documentations says about it:
Providers can specify custom payload values outside the Apple-reserved aps namespace. Custom values must use the JSON structured and primitive types: dictionary (object), array, string, number, and Boolean.
So in your case you should do something like:
{
"aps": {
"alert": "Hello World",
"sound": "default"
},
"Person": {
"Address": "this is a test address",
"Name": "First Name",
"Number": "023232323233"
}
}
Therefore you can read your custom payload with looking for it's key in main JSON, rather than in "aps":
NSLog(#"%#",notification['Person']['Address']);
Above will output:
this is a test address
You could find more about custom payloads, along with some examples in Apple docs.
Reference:link
if user is not prevented from settings, aps.alert is always displayed
{
"aps": {
"badge": 10,
"alert": "Hello world!",
"sound": "cat.caf"
},
"job_id": 1
}
update your notification structure like this, send data under some other key like "job_id"

Apple watch real response data

Can you print and show me the output of this with real device I need to know the format of it.
- (void)didReceiveRemoteNotification:(NSDictionary *)remoteNotification withCompletion:(void (^)(WKUserNotificationInterfaceType))completionHandler
{
// This method is called when a remote notification needs to be presented.
// Implement it if you use a dynamic notification interface.
// Populate your dynamic notification interface as quickly as possible.
// After populating your dynamic notification interface call the completion block.
NSLog(#"%#",remoteNotification);
completionHandler(WKUserNotificationInterfaceTypeCustom);
}
This is the Payload response for the question
{
"aps": {
"alert": {
"body": "Test message",
"title": "Optional title"
},
"category": "myCategory"
},
"WatchKit Simulator Actions": [
{
"title": "First Button",
"identifier": "firstButtonAction"
}
],
"customKey": "Use this file to define a testing payload for your notifications. The aps dictionary specifies the category, alert text and title. The WatchKit Simulator Actions array can provide info for one or more action buttons in addition to the standard Dismiss button. Any other top level keys are custom payload. If you have multiple such JSON files in your project, you'll be able to select them when choosing to debug the notification interface of your Watch App."
}

Resources