我想在我的 iOS 应用程序上设置我的本地通知,以便当用户向左滑动然后点击查看时,通知上的消息会显示在出现的视图中。我想这样做是因为如果消息很长,则会将其截断,以便通知中仅显示消息的第一部分。
这是我的代码。它的工作原理和我知道的一样多。当用户点击 View 按钮时,它只显示一个空白视图。
let content = UNMutableNotificationContent()
content.categoryIdentifier = "HELLO"
content.title = "Hello World!"
content.body = "Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda."
if #available(iOS 12.0, *) {
content.summaryArgument = "summaryArgument"
content.summaryArgumentCount = 5
} else {
// Fallback on earlier versions
}
var dateComponents = DateComponents()
dateComponents.second = 0
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
// Create the request
let uuidString = UUID().uuidString
let request = UNNotificationRequest(identifier: uuidString,
content: content, trigger: trigger)
// Schedule the request with the system.
center.add(request) { (error) in
if error != nil {
print("error=", error?.localizedDescription as Any)
}
}