gpt4 book ai didi

iOS 11 用户自定义声音通知

转载 作者:搜寻专家 更新时间:2023-10-31 22:55:50 25 4
gpt4 key购买 nike

我在执行 Apple 的基本示例代码时遇到了麻烦,如下所示

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SchedulingandHandlingLocalNotifications.html#//apple_ref/doc/uid/TP40008194-CH5-SW3

这是我的代码;这是非常“教科书的例子”。我目前收到“‘init(named:)’不可用”的错误

    let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationString(forKey:"testreminder!", arguments: nil)
content.body = NSString.localizedUserNotificationString(forKey:"Reminder body.", arguments: nil)

content.sound = UNNotificationSound(named: "test.aiff");
content.categoryIdentifier = "myCategory"

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "test.aiff", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

编辑:在尝试这些建议后,这是代码,但它不起作用。它给出了一个'init(named:)'不可用

    let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationString(forKey:"testreminder!", arguments: nil)
content.body = NSString.localizedUserNotificationString(forKey:"Reminder body.", arguments: nil)

content.sound = UNNotificationSound.init(named: "test.aiff")
content.categoryIdentifier = "myCategory"

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "test.aiff", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)

最佳答案

  1. 使用 UNNotificationSoundName 结构定义声音名称。

https://developer.apple.com/documentation/usernotifications/unnotificationsoundname

let soundName = UNNotificationSoundName("test.aiff")
content.sound = UNNotificationSound(named: soundName)
  1. 并确保在文件检查器中选中目标成员资格 以获取声音文件。 File inspector Screenshot

关于iOS 11 用户自定义声音通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47586751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com