Local Notification sound not came when App in foreground iOS Swift
Solution:
If app is in foreground the notification sounds will not be played.So you have to manually play the sound to notify the user.Use the below code to play the sound
If app is in foreground the notification sounds will not be played.So you have to manually play the sound to notify the user.Use the below code to play the sound
var sound:AVAudioPlayer!
if appstate.applicationState == .active {
let sound = "soundname"
let alertSound = NSURL(fileURLWithPath: Bundle.main.path(forResource: sound, ofType: "mp3")!)
do {
self.sound = try AVAudioPlayer(contentsOf: alertSound as URL)
self.sound.prepareToPlay()
DispatchQueue.main.async {
self.sound.play()
}
} catch {
}
}
Comments
Post a Comment