I would like to set up my local notification on my iOS app so that when the user swipes left and then taps on View, the message on the notification shows in the view that appears. I want to do this because if the message is long, it is cut off so that only the first part of it is shown in the notification.
Here is my code. It works as much as I know how to do. When the user taps on the View button, it only shows a blank 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)
}
}
If the problem is that the body is too long for the standard alert, use a UNNotificationContentExtension to provide a secondary interface. That way, the user can see the whole body right there as part of the alert.
If the problem is that you want to be notified back in the app when the user taps View, make yourself the UNUserNotificationCenterDelegate and implement userNotificationCenter(_:didReceive:withCompletionHandler:)
.