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

时间:2018-09-05 06:34:34

标签: ios swift audio

| diapason | number_of_users |
|----------|-----------------|
|     0-10 |               1 |
|    10-50 |               1 |
|      >50 |               1 |

如果fcm push发送了foreGround Audio,则播放

但是在backGround中没有播放音频

如何玩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]) } AudioServicesPlaySystemSound 在背景中 功能背景模式已检查

Swift 4,iOS 11

1 个答案:

答案 0 :(得分:0)

您必须设置播放音频的背景模式,然后才能执行此操作。此答案iOS background audio not playing中对此进行了详细说明。

enter image description here