我尝试过所有可想到的方式来播放自定义声音名称 (在Mac上格式化为aiff,wav,使用在线工具格式化,使用以前工作的旧声音,移动文件,重命名文件,确保歌曲不到30秒,清理项目,删除应用程序,重新启动iPhone,删除derivedData。
基本上一切,但它不起作用。我猜它一定是个bug。我已经尝试了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])