gpt4 book ai didi

iOS Swift 如何在后台播放 AudioServicesPlaySystemSound 或 AudioServicesPlayAlertSound

转载 作者:行者123 更新时间:2023-11-30 11:10:59 29 4
gpt4 key购买 nike

extension AppDelegate : UNUserNotificationCenterDelegate {

// Receive displayed notifications for iOS 10 devices.
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

let userInfo = notification.request.content.userInfo

print("userNotificationCenter-UNNotificationPresentationOptions")
// With swizzling disabled you must let Messaging know about the message, for Analytics
Messaging.messaging().appDidReceiveMessage(userInfo)

if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}

// Print full message.
print(userInfo)

// Change this to your preferred presentation option

// AudioServicesPlayAlertSound(1016)
AudioServicesPlaySystemSound(1016)
completionHandler([.alert,.badge])
}

如果 fcm 推送在前台发送音频正在播放

但在后台未播放音频

如何播放AudioServicesPlaySystemSoundAudioServicesPlayAlertSound在后台功能背景模式已检查

Swift 4、iOS 11

最佳答案

您必须设置播放音频的后台模式才能执行此操作。这个答案iOS background audio not playing中有详细描述。 .

enter image description here

关于iOS Swift 如何在后台播放 AudioServicesPlaySystemSound 或 AudioServicesPlayAlertSound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52178539/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com