My custom sounds for remote notifications suddenly stopped working today. They worked yesterday and played fine. Then today, out of the blue, they stopped working. I did not update any code or make any database changes. The custom sounds just suddenly stopped. All my notifications play the default iOS sound now. Very annoying.
Here is my Swift
code in app delegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 10.0, *) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
FirebaseApp.configure()
Messaging.messaging().delegate = self
return true
}
And here is my Typescript code from VS Code:
function sendNewUserAlertToDevices() {
const db = admin.database()
const statsRef = db.ref('stats')
// get current new user count
return statsRef.child('newUserCount').once('value').then((statsSnap: any) => {
const oldUserCount = statsSnap.val()
// update new user count by +1
const newUserCount = oldUserCount + 1
// console.log('new user count:', newUserCount)
return statsRef.update({
'newUserCount': newUserCount
}).then(function (_response: any) {
// 1. get list of FCM tokens from database
return statsRef.child('fcmTokens').once('value').then((tokenSnap: any) => {
// console.log('hello 1')
const fcmTokens = tokenSnap.val()
// console.log(fcmTokens)
// 2. iterate over array of tokens to get individual FCM token
for (const key in fcmTokens) {
if (fcmTokens.hasOwnProperty(key)) {
// console.log(key + ' -> ' + fcmTokens[key])
const fcmToken = fcmTokens[key]
// 3. send message to each devices that has MP Admin installed on it
const payload = {
notification: {
title: 'New User',
body: 'Moneypants has a new download, yo!',
sound: '27-96_Xylophone_Sneaky_Short.mp3',
badge: String(newUserCount)
}
}
admin.messaging().sendToDevice(fcmToken, payload)
}
}
}).catch(function (error: any) {
console.log('Error getting fcmTokens:', error)
})
})
})
}
Not sure where the error lies. From what I can tell, all my code is up to date. As I said, everything worked just fine yesterday. I'm guessing there is some new protocol that I have to update to, but I don't know where that would be.