如何在FCM for iOS中创建自定义声音? FCM自定义声音在iOS中恢复为默认声音

问题描述

我的自定义远程通知声音今天突然停止工作。他们昨天工作正常,表现良好。然后,今天,他们突然失去了工作。我没有更新任何代码或进行任何数据库更改。自定义声音突然停止了。我所有的通知现在都播放认的iOS声音。非常烦人。

这是我在应用程序委托中的Swift代码

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,.sound],categories: nil)
        application.registerUserNotificationSettings(settings)
    }
    
    application.registerForRemoteNotifications()
    
    FirebaseApp.configure()
    
    Messaging.messaging().delegate = self
            
    return true
}

这是我来自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)
        })
    })
})
}

不确定错误在哪里。据我所知,我所有的代码都是最新的。正如我所说,昨天一切正常。我猜想有一些新协议需要更新,但是我不知道会在哪里。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)