[英]UILocalNotification custom soundName not playing
我嘗試了各種可能的方式來播放自定義聲音名稱(在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中修復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.