Reputation: 31
I am currently having a problem where custom sounds in UILocalNotifications only work the first time the app is installed. After installing the app a second time (i.e. to simulate an upgrade) on top of itself, the sound goes back to the default sound, even for newly created notifications. I created a new test project to test the bare minimum and the problem still repros. Below is my ViewController:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let notification = createNotification()
UIApplication.shared.scheduleLocalNotification(notification)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func createNotification() -> UILocalNotification {
let tenSecondsLater = Date().addingTimeInterval(10)
let notification = UILocalNotification()
notification.fireDate = tenSecondsLater
notification.alertTitle = "Test Notification Title"
notification.alertBody = "body"
notification.soundName = "alarm-20secs.wav"
return notification
}
}
Permissions are set correctly in AppDelegate:
UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound], categories: nil))
Repro steps:
I have already tried calling cancelAllLocalNotifications(), but it doesn't seem to change anything. Force kill doesn't reproduce the problem, only upgrading. After upgrade, the sound can still be played using AVPlayer, so it's not like the file gets deleted; only local notifications are affected.
I am well aware that UILocalNotification was deprecated in iOS 10, but the new UserNotification framework does not support repeating notifications, which is a feature I need. This problem happens in both sim and device running iOS 10 and 10.0.2. I couldn't find any other threads describing this particular problem, for most other people they couldn't get their sound to work at all. In this case, it works fine but only after re-installing the app. This will be a problem when I release a new version, since the upgrade path would break notification sounds, which is vital for my app.
Upvotes: 3
Views: 567
Reputation: 31
Probably by now, you are aware that this is caused by a bug in ios 10..
a reboot of the phone (after the app update) will also fix it.
Upvotes: 2