Firebase iOS推送通知自定义声音不播放?
我在iOS应用程序中使用firebase推送通知服务,该应用程序是使用swift 3开发的。目前我收到通知。但我已经为通知警报配置了自定义声音。当应用程序关闭时,我会得到一个默认的声音,而不是剪切的声音。但我想播放自定义声音。我该怎么做? 以下是我所做的:Firebase iOS推送通知自定义声音不播放?,firebase,swift3,apple-push-notifications,firebase-cloud-messaging,Firebase,Swift3,Apple Push Notifications,Firebase Cloud Messaging,我在iOS应用程序中使用firebase推送通知服务,该应用程序是使用swift 3开发的。目前我收到通知。但我已经为通知警报配置了自定义声音。当应用程序关闭时,我会得到一个默认的声音,而不是剪切的声音。但我想播放自定义声音。我该怎么做? 以下是我所做的: import UIKit import UserNotifications import Firebase import FirebaseInstanceID import FirebaseMessaging import Googl
import UIKit
import UserNotifications
import Firebase
import FirebaseInstanceID
import FirebaseMessaging
import GoogleMaps
import GooglePlaces
import GooglePlacePicker
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//For FireBase Configs
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
FirebaseApp.configure()
//FireBase Configs
return true
}
func application(_ application: UIApplication,open url: URL,sourceApplication: String?, annotation: Any) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application,open: url as URL!,sourceApplication: sourceApplication,annotation: annotation)
}
//FireBase Notifications Begins
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
//play alert sound
utilityHelper.playAudio(fileName: "udio", fileExtenstion: "mp3")
let json = JSON(userInfo)
NSLog("Received a Notificat`ion: \(json)")
completionHandler(UIBackgroundFetchResult.newData)
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
NSLog("show notification")
completionHandler(UNNotificationPresentationOptions.alert)
}
func application(received remoteMessage: MessagingRemoteMessage) {
}
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
NSLog("Refreshed Firebase registration token: \(fcmToken)")
}
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken as Data
NSLog("Register FireBase Token.")
}
//FireBase Notifications End
}
我如何做到这一点,任何帮助都将不胜感激。我最近发现,在ios 9下的target上,自定义声音播放效果不如在ios 10.0*设备上。
因此,只需将构建目标设置为>=9或使用iOS>=10.1的设备,现在看来这是一个答案。干得好。作为撰写好答案的提示:搜索文档和类似的内容,以备份您的陈述,表明您在帮助用户方面投入了时间和精力。但一定要先读