我已经尝试了所有可以想到的方法来播放自定义声音名称 (在 Mac 上格式化为 aiff、wav,使用在线工具格式化,使用以前可以使用的旧声音,移动文件,重命名文件,确保歌曲在 30 秒以下,清理项目,删除应用程序,重新启动 iPhone,删除衍生数据。
基本上一切都行,但就是行不通。我猜这一定是一个错误。我已经尝试了 2-3 天并阅读了所有 SO 问题和论坛 - 没有运气。
所以我放弃了,只想播放铃声,最好是 29 秒长的铃声。 我怎样才能做到这一点?除了 UILocalNotificationDefaultSoundName 之外还有其他铃声/系统声音吗?
任何帮助将非常感激!
func pushRegistry(registry: PKPushRegistry, didReceiveIncomingPushWithPayload payload: PKPushPayload, forType type: String) {
print("\n\n## DID RECEIVE NOTIFICATION ## \n\n")
let data = payload.dictionaryPayload
if let type = data["type"] as? String {
if type == "MESSAGE_NOTE" {
print("Notification is Message")
let notification = UILocalNotification()
notification.alertTitle = "App message"
notification.soundName = UILocalNotificationDefaultSoundName
notification.userInfo = ["type":type]
notification.alertBody = "New message"
notification.alertAction = "Accept"
UIApplication.sharedApplication().applicationIconBadgeNumber += 1
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
} else if type == "INCOMING_CALL" {
print("Notification is incoming call")
let notification = UILocalNotification()
notification.alertTitle = "App call"
notification.soundName = "Simple_ring_tone_29s.aiff"
notification.userInfo = ["type":type]
notification.alertBody = "Incoming call"
notification.alertAction = "Accept"
UIApplication.sharedApplication().applicationIconBadgeNumber += 1
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
}
}
}
通知设置已在另一个 VC 中注册
let notificationSettings: UIUserNotificationSettings! = UIApplication.sharedApplication().currentUserNotificationSettings()
if !notificationSettings.types.contains([.Badge, .Sound, .Alert]) {
let notificationTypes: UIUserNotificationType = [.Badge, .Sound, .Alert]
let notificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
在 didFinishLaunchingWithOptions 中
voipRegistry = PKPushRegistry(queue: dispatch_get_main_queue())
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = Set([PKPushTypeVoIP])
最佳答案
此问题已从 iOS 10.1 beta 2 开始修复。
关于ios - UILocalNotification 自定义 soundName 未播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39945322/