我想在我的 iOS 应用程序上设置我的本地通知,以便当用户向左滑动然后点击“查看”时,通知上的消息会显示在出现的 View 中。我想这样做是因为如果消息很长,它会被截断,以便通知中只显示消息的第一部分。
这是我的代码。它的工作原理和我知道的一样。当用户点击“查看”按钮时,它只会显示一个空白 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)
}
}
最佳答案
如果问题是正文对于标准警报而言太长,请使用 UNNotificationContentExtension 提供辅助接口(interface)。这样,作为警报的一部分,用户就可以看到整个 body 。
如果问题是您希望在用户点击“ View ”时在应用中收到通知,请让自己成为 UNUserNotificationCenterDelegate 并实现 userNotificationCenter(_:didReceive:withCompletionHandler:)
。
关于ios - 当用户点击 iOS 中本地通知上的“查看”按钮时,如何设置 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56942204/