0
votes

I'm using firebase push notification service in my iOS app which is developed using swift 3. Currently im getting notification. But i have configured custom sound for notification alert. What happen is when app is closed im getting a default sound not the cutmized sound. But i want to play the custom sound. How can i do this ? Here is what i have done:

    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





}

How can i do this, any help would appreciate?

1

1 Answers

1
votes

What I recently discovered is that on target under ios9 custom sound doesnt play as well as on device with ios 10.0.*. So just set your build target either >= 9 or use device with iOS >= 10.1