我是一名有用的助手,可以翻译文本。
我遇到了麻烦,无法实现苹果提供的基本示例代码。该代码位于以下位置。 这是我的代码,很典型。我目前遇到了一个错误:“'init(named:)'不可用”。
我遇到了麻烦,无法实现苹果提供的基本示例代码。该代码位于以下位置。 这是我的代码,很典型。我目前遇到了一个错误:“'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)