【问题标题】:UILocalNotification Custom Sound not working after updating app更新应用程序后 UILocalNotification 自定义声音不起作用
【发布时间】:2017-02-08 11:58:06
【问题描述】:

我目前遇到的问题是 UILocalNotifications 中的自定义声音仅在第一次安装应用程序时才有效。在第二次安装应用程序(即模拟升级)后,声音会恢复为默认声音,即使是新创建的通知也是如此。我创建了一个新的测试项目来测试最低限度的问题,但问题仍然存在。下面是我的 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
}

}

AppDelegate 中权限设置正确:

UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound], categories: nil))

复制步骤:

  1. 在 Xcode 中按 Run 安装应用程序。按主页进入后台应用
  2. ~10 秒后,警报显示正常并播放正确的声音
  3. 在 Xcode 中按 Run 再次安装应用程序。按主页进入后台应用
  4. ~10 秒后,警报出现,但现在播放默认声音。

我已经尝试调用 cancelAllLocalNotifications(),但它似乎并没有改变任何东西。强制杀死不会重现问题,只会升级。升级后仍然可以使用AVPlayer播放声音,所以文件不会被删除;只有本地通知会受到影响。

我很清楚 UILocalNotification 在 iOS 10 中已被弃用,但新的 UserNotification 框架不支持重复通知,这是我需要的功能。此问题发生在运行 iOS 10 和 10.0.2 的 sim 卡和设备中。我找不到任何其他线程来描述这个特定问题,对于大多数其他人来说,他们根本无法让他们的声音正常工作。在这种情况下,它可以正常工作,但只有在重新安装应用程序后才能正常工作。当我发布新版本时,这将是一个问题,因为升级路径会破坏通知声音,这对我的应用程序至关重要。

【问题讨论】:

    标签: ios swift xcode audio uilocalnotification


    【解决方案1】:

    现在,您可能已经知道这是由 ios 10 中的一个错误引起的..

    重启手机(应用更新后)也可以解决问题。

    【讨论】:

    • 您是否碰巧有关于此 ios10 问题的雷达参考/链接?
    • 删除应用程序并重新安装它为我完成了这项工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-22
    • 2019-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多