【发布时间】:2016-08-09 11:39:06
【问题描述】:
我正在使用一个示例项目来处理新通知,从 Swift 2.2 过渡到 Swift 2.3,也从 iOS 9 过渡到 iOS 10。我正在使用下面的代码,取自 this example:
@available(iOS 10.0, *)
func setupAndGenerateLocalNotification() {
// Register an Actionable Notification
let highFiveAction = UNNotificationAction(identifier: NotificationActions.HighFive.rawValue, title: "High Five", options: [])
//next line is an error:
let category = UNNotificationCategory(identifier: "wassup", actions: [highFiveAction], minimalActions: [highFiveAction], intentIdentifiers: [], options: [.customDismissAction])
//Cannot invoke initializer for type 'UNNotificationCategory' with an argument list of type '(identifier: String, actions: _, minimalActions: _, intentIdentifiers: _, options: _)'
UNUserNotificationCenter.current().setNotificationCategories([category])
let highFiveContent = UNMutableNotificationContent()
highFiveContent.title = "Wassup?"
highFiveContent.body = "Can I get a high five?"
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let highFiveRequestIdentifier = "sampleRequest"
let highFiveRequest = UNNotificationRequest(identifier: highFiveRequestIdentifier, content: highFiveContent, trigger: trigger)
UNUserNotificationCenter.currentNotificationCenter().addNotificationRequest(highFiveRequest) { (error) in
// handle the error if needed
print(error)
}
}
我得到的错误是
Cannot invoke initializer for type 'UNNotificationCategory' with an argument list of type '(identifier: String, actions: _, minimalActions: _, intentIdentifiers: _, options: _)'
【问题讨论】:
标签: ios notifications swift2 ios10