如何解决收到通知时的默认声音和振动
我正在尝试向我的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 举报,一经查实,本站将立刻删除。