Firebase push notifications custom sound - ios

I am currently working on an app and I have implement firebase Push Notification service into my app. I am recieving notification on my iphone but I am unable to set the custom alert sound that I want.
I added the sound as a .caf
I added the sound to the Copy Bundle Resources
using print (userInfo) I have collected this data that is incomming from Firebase
aps: {
alert = {
body = MSG;
title = Title;
};
sound = default;}, {...}, sound: alarm.caf
I understand where the problem is, I just dont understand how to fix it so that the app plays my custom notification sound.

Problem with Firebase is that you can not send sound parameter like custom parameter with Firebase Console, if you try this as you do, you will get this parameter in app outside of aps Dictionary and the system will not recognize it as a sound to be played although the sound file is into the project.
The only solution for this problem is you have some API/server through which you'll be sent a Firebase notification. When server send you a notification with sound param it will be within aps Dictionary and application will play this sound when the notification arrives.

After much research I have not found any solution.
Under Firebase Messaging Docs, and
Table 2a. iOS — keys for notification messages
it is indicated that Firebase does allow for the Sound key to be included in the payload but as seen in the code printed by didRecieveRemoteNotification,
aps: {
alert = {
body = MSG;
title = Title;
};
sound = default;}, {...}, sound: alarm.caf
Firebase doesn't include the Sound key inside the aps hence not calling the sound key by the app.
The workaround that I used for my app is Easy APNs Provider which is a handy and easy app to use for development purposes, a major issue is that it doesn't have the ability to register and remove notifications automatically.
lastly: for Push Notifications to my published apps, I have opted for a dedicated server which I run off of my website

It's been over 5 years, but if someone still looking for an answer, here is what I did.
Make sure you have configured Firebase Messaging & receiving Notifications.
Add .caf ( sound file ) to the app. It must be visible on
'Target' - > 'Build Phases' & then under 'Copy Bundle Resources'
Delete the app from the device ( This is important )
I use Postman as my server, so message format would be,
{
"notification": {
"title": "Hello",
"sound":"small_message.caf",
"body": "You have a new Job"
},
"to": "your device token"
}

Related

Ionic Capacitor - Push Notification not making sound on iOS

We're using this guide to create a pretty routine push notification system.
We have everything working and push notifications are coming through. On Android, the push notifications make the default alert sound. On iOS however, no sound is made.
How can we configure the push notification to use the default alert sound on iOS (we don't want to create/manage a custom alert sound).
I've already configured the presentationOptions setting in the capacitor.config.json file.
{
"appId": "REDACTED",
"appName": "REDACTED",
"bundledWebRuntime": false,
"npmClient": "npm",
"webDir": "www",
"plugins": {
"PushNotifications": {
"presentationOptions": ["badge", "sound", "alert"]
}
}
}
Push notifications appearance in foreground
On iOS you can configure the way the push notifications are displayed when the app is in foreground by providing the presentationOptions in your capacitor.config.json as an Array of Strings you can combine.
Possible values are:
badge: badge count on the app icon is updated (default value)
sound: the device will ring/vibrate when the push notification is received
alert: the push notification is displayed in a native dialog
An empty Array can be provided if none of the previous options are desired. pushNotificationReceived event will still be fired with the push notification information.
"plugins": {
"PushNotifications": {
"presentationOptions": ["badge", "sound", "alert"]
}
}
push-notifications-appearance-in-foreground
What are you using to send the push notification?
I followed the same capacitor guide and faced the same issue, then I did a test by sending the notification from the Firebase Cloud Messaging console and it worked on iOS (the notification made a sound).
I found later that in the code I was using to send the notification (the firebase nodejs admin SDK), I didn't provide a value for the sound attribute. I assumed that since it's not required and it worked on Android, it should also work on iOS. I was wrong!
import * as admin from 'firebase-admin';
const message: admin.messaging.MessagingPayload = {
data: {
...
},
notification: {
title: 'title',
body: 'body',
sound: 'default' // Add this line
},
};
await admin.messaging().sendToDevice(tokens, message);
The docs says that this attribute is only for the Android platform, which is why I didn't set it at first.
PS: I also added the presentationOptions setting mentioned above in the capacitor.config.json file.

Receiving Push Notification on the Iphone

Hello I'm stuck and I need help.
I have an iOS application build with Angular2 + Cordova + cordova-firebase-plugin + xcode.
I have setup the app on developers.apple.com and firebase.console website.
Now when I try to send a Notification message, I don't receive it on Iphone at all.
If the application is runing in the foreground, I see in the debug console that the notification was received, but it is not displayed on the Iphone.
Message from console:
Received data message: {
"collapse_key" = "com.example.app"
from = 793840040300;
notification = {
body = "example test notification message";
e = 1;
}
}
What I don't see here: notification title. (The notifications are working in Android, but not in iOS).
There were no any prompts about enabling the notifications (permissions prompt).
I trieed to setup APNS-FCM connectivity via .p12 Certificates and via .p8 Certificates (via the key). Boths atemmpts did not give me positive result...
One more moment:
IF the application is running in the background - I don't see the message in the console until I will open the app. When I open the app, the message appears in the console, if it was sent while the app was in foreground..
I viewed many different guides, but I didn't get any result.
I read that emulators does not support the push notifications, so I connected a real device via USB. And it behaves the same - no push notification received - only the message in the console.
Please, help me.
Make sure you are sending both the title and body in the payload. I had the issue (in Android) that when not sending the message item, the notification would not show up in the notifications bar. The same applies for iOS, but in this case, the variables are title and body.
If the right variables are not found in the payload, both Android, iOS and Windows Phone will consider it a background notification that is silently delivered to the app (once it's opened). Notifications will not wake an unloaded app, the app is launched by the notification item once it's selected from the notifications bar in this case.
Try sending the default payload from the documentation to test it:
{
"aps": {
"alert": { // alternatively just a string: "Your Message",
"title": "A short string describing the purpose of the notification",
"body": "The text of the alert message",
// localization of message is possible
"launch-image": "The filename of an image file in the app bundle, with or without the filename extension. The image is used as the launch image when users tap the action button or move the action slider"
},
"badge": 5, // Number to show at App icon
"content-available": "0", // configure background updates, see below
"category": "identifier", // Provide this key with a string value that represents the notification’s type
"thread-id": "id", // Provide this key with a string value that represents the app-specific identifier for grouping notifications
"sound": "default" // play default sound, or custom sound, see [iOS Sound](#sound-1) section
},
"custom_key1": "value1",
"custom_key2": "value2"
}
If this doesn't work, please include the entire content of the payload you are sending to APNS, from the server side.
Edit: make sure you are sending your payload fields in UTF-8 encoding to all push services.

Localized Notifications iOS 10 using FCM

We have a Django backend server using pyfcm to deliver Notifications throgh Firebase Cloud Messaging (FCM). I just updated to the today released Version 1.3.0. I want to send a notification using the loc-key and loc-args parameters so it can be displayed in the language the user is using on his phone. The notification reaches the device, it vibrates and makes the default sound for a new notification, but it will not displayed. It just happens nothing except for the sound and vibration.
This is the payload generated by the server which is sent to the fcm endpoint:
{
"notification": {
"loc-args": ["Demo (#demo)"],
"loc-key": "notification-follow",
"sound": "Default"
},
"priority": "high",
"to": "..."
}
On the client side, this is what is received by the phone:
[
AnyHashable("gcm.message_id"):0:1496257581534217 %f910cc44f910cc44,
AnyHashable("aps"):{
category = profile;
sound = Default;
},
AnyHashable("gcm.notification.alert"):{
"title-loc-key":" notification-follow",
"title-loc-args":[
"Demo (#demo)"
]
}
]
Is there anything I have to do before the message is displaying? Sending the message without the loc-key and loc-args but with message-body presents the notificaion on the device. Maybe the payload is wrong? How should it look like to do what I want?
The key, notification-follow in this case, is listed and translated in the Localizable.strings files in any available language.
Ok, problem solved. It was pyFCM. I thought it would be an error with this library, so the developer pseudo-fixed it. But it worked properly, and now it doesn't work anymore. The trick is to give body_loc_args an array, otherwise it will give you an InvalidParameters error.

Play system sound on push notification

I display the list of sound retrieved from "/System/Library/Audio/UISounds".When user select any sound, I send the name of sound to the server. When server send the push notification , it configure that name in payload ,
But still iOS play the default sound. What Do I have to do to play the selected sound.
it is possible in local notification. will attached in the payload, key ="sound"
aps =
{
alert = "test example notification message";
sound = "example.caf";
};
example.caf file import in your xcode project.
you will try the same concept may be it will works.

iOS8.2 not playing custom alert sound from parse.com app

I have successfully set up a push notification app via Parse.com. App is installed on iPhone 5s running iOS8.2. App code in Swift
If I send a regular push notification, it comes up fine, but plays the very short buzz (like 'quick' vibration or very short standard 'note' text alert, rather than what I have set as the standard text alert.
(If I send an iMessage, and have the alert tone set to 'chord', it plays that OK)
If I instead send the dictionary version with a custom sound included in the app bundle (yes, I converted it in terminal per Apple instructions), it still does the same as above. I cannot get it to play any custom alert sounds.
It makes no difference if I originate the push from the app, or from the button on Parse.com
Just as the other person said, ensure that your file is in the correct format (you want it in an generally .caf files)
Also, be sure that you have entered the correct file name when you are sending the push notification if you are using client push.
Example from Parse Docs:
let data = [
"alert" : "The Mets scored! The game is now tied 1-1!",
"badge" : "Increment",
"sounds" : "cheering.caf" //Ensure the file exists in your project
]
let push = PFPush()
push.setChannels(["Mets"])
push.setData(data)
push.sendPushInBackground()

Resources