gpt4 book ai didi

ios - UILocalNotification 声音不工作

转载 作者:行者123 更新时间:2023-11-28 11:17:24 25 4
gpt4 key购买 nike

我对 UILocalNotification 的声音有一些疑问。我在应用程序委托(delegate)中拥有用户权限。

这是我的代码:

var nottypes:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
var notsettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: nottypes, categories: nil)
application.registerUserNotificationSettings(notsettings)

通知代码:

var notification:UILocalNotification = UILocalNotification()
notification.alertBody = "Simple"
notification.alertTitle = "Back To App!"
notification.fireDate = NSDate(timeIntervalSinceNow: 20)
notification.soundName = "Chord"
UIApplication.sharedApplication().scheduleLocalNotification(notification)

最佳答案

在 S.O. 上发布问题之前,您应该始终查看文档。如果您阅读 soundName's 定义的第一行它说的属性:

For this property, specify the filename (including extension) of a sound resource in the app’s main bundle or UILocalNotificationDefaultSoundName to request the default system sound. When the system displays an alert for a local notification or badges an app icon, it plays this sound. The default value is nil (no sound). Sounds that last longer than 30 seconds are not supported. If you specify a file with a sound that plays over 30 seconds, the default sound is played instead.

所以尝试:

notification.soundName = "Chord.mp3"   // use .mp3 or your file extension if it is not an mp3 

关于ios - UILocalNotification 声音不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30872630/

25 4 0
文章推荐: jquery - 从文本文件生成自动排序的 HTML 表格?
文章推荐: javascript - 正则表达式匹配除前两个字符之外的所有内容
文章推荐: css - HTML5/CSS : possible to define a