我在使用swift 3开发的iOS应用程序中使用firebase推送通知服务。目前我正在收到通知。但我已为通知警报配置了自定义声音。当app关闭时我会发现默认声音不是切割声音。但我想播放自定义声音。我怎样才能做到这一点 ? 这就是我所做的:
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
}
我怎么能这样做,任何帮助都会欣赏?
答案 0 :(得分:1)
我最近发现的是ios9下的目标定制声音与ios 10.0。*的设备不同。 因此,只需将您的构建目标设置为> = 9或使用iOS> = 10.1
的设备