0

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)
    }
}
daniel
  • 1,446
  • 3
  • 29
  • 65

1 Answers1

1

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:).

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I don't need the notification to communicate with the app. I am using UNNotificationContentExtension. I don't know how to adjust the size of the notification. I would like the user to still view the message when she taps on View, that way she can scroll the view to see the entire message, whereas she can't do that on the main body of the notification. – daniel Jul 08 '19 at 20:45
  • Yes, you can have a scrollable message using the UNNotificationContentExtension interface. – matt Jul 08 '19 at 21:05
  • The message body and the title appear too far down at the bottom of the view that appears when the user taps View. – daniel Jul 08 '19 at 21:15