1

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.

Phontaine Judd
  • 428
  • 7
  • 17
  • Same here. Custom sounds all of a sudden stopped working yesterday on iOS devices. After doing some digging, the only thing I can think of to try is to migrate to firebase's newer http v1 api to send push notifications. Apparently, the new version allows you to customize things for different platforms. https://firebase.google.com/docs/cloud-messaging/migrate-v1 – SKim Aug 14 '20 at 19:45
  • Okay, so it's not just me. That makes me feel better. I thought I had somehow damaged my code. I have spent hours and hours trying to track down the culprit code. I'll do some more digging and try to figure out where to go from here. Thanks for your response. – Phontaine Judd Aug 15 '20 at 06:37
  • We moved to the newer http v1 firebase api and the custom sounds are working now. – SKim Aug 15 '20 at 11:59
  • @SKim how did you update to the newer http v1 firebase api? The link on the Firebase site is dead. I'm having trouble tracking down the info. – Phontaine Judd Aug 16 '20 at 06:34
  • 1
    Okay, so after four days of research and banging my head against the wall, the custom sounds are back! I reverted to my exact same code from four days ago, so I know it wasn't my code that changed. It just magically fixed itself. Aargh! There goes four days of work. :-/ – Phontaine Judd Aug 19 '20 at 03:21
  • https://stackoverflow.com/a/70939615/2126077 check my answer here – Heshan Sandeepa Feb 01 '22 at 11:13

0 Answers0