收到通知时的默认声音和振动

问题描述

我正在尝试向我的ios应用发送推送通知。该设备可以成功接收推送通知,我正在尝试同时接收声音和振动。收到通知后,它只是保持沉

在我的应用代理中,我试图添加

   func application(_ application: UIApplication,didReceiveRemoteNotification userInfo: [AnyHashable : Any],fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    print("serInfo=",userInfo)
    if UIApplication.shared.applicationState == .active {
      AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
        
    }
    else if UIApplication.shared.applicationState == .background {
        AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
    }
}

,但通知仍通过静发出。有没有办法实现认的声音和振动?

我也已经有

   func attemptToRegisterForNotifications(application: UIApplication) {

  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()
}

设置,以便用户已经同意接收振动和声音。

var payload = {
  notification: {
    title: userThatSent.name + ' sent you a message',body: message.text
    "sound" : "default"

     }
   };  

添加以上内容后,我会在终端中收到以下问题。

Error: Error occurred while parsing your function triggers.

/Users/wilcox.323/Downloads/OddJobs-master/functions/index.js:220
        "sound": "default"
        ^^^^^^^

SyntaxError: Unexpected string
    at wrapSafe (internal/modules/cjs/loader.js:1116:16)
    at Module._compile (internal/modules/cjs/loader.js:1164:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    at Module.load (internal/modules/cjs/loader.js:1049:32)
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)
    at Module.require (internal/modules/cjs/loader.js:1089:19)
    at require (internal/modules/cjs/helpers.js:73:18)
    at /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:15:15
    at Object.<anonymous> (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:53:3)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)

解决方法

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

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

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