【问题标题】:Firebase iOS push notification custom sound not playing?Firebase iOS推送通知自定义声音没有播放?
【发布时间】:2017-10-26 06:51:56
【问题描述】:

我在使用 swift 3 开发的 iOS 应用程序中使用 firebase 推送通知服务。目前我正在收到通知。但我已经为通知警报配置了自定义声音。发生的情况是当应用程序关闭时,我得到的是默认声音,而不是经过剪辑的声音。但我想播放自定义声音。我怎样才能做到这一点 ? 这是我所做的:

    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





}

我该怎么做,有什么帮助吗?

【问题讨论】:

    标签: firebase swift3 apple-push-notifications firebase-cloud-messaging


    【解决方案1】:

    我最近发现,在 ios9 自定义声音下的目标上播放效果不如在 ios 10.0.* 的设备上播放。 因此,只需将您的构建目标设置为 >= 9 或使用 iOS >= 10.1 的设备

    【讨论】:

    • 现在看起来像是一个答案。好工作。作为编写好答案的提示:搜索文档和类似内容以支持您的陈述,以表明您投入时间和精力来帮助用户。但请务必先阅读this meta post abaout link-only answers
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多