Group Group Group Group Group Group Group Group Group

Chapter 11 TextInputNotificationResponse not working



In chapter 11 I am unable to pick up the text response that is sent back by the user.

I have the map displaying fine, but when you type a response and press send nothing happens; the print statements are not triggered.

When the map is displayed in the notification the following appears in the output window:

2019-03-28 09:25:58.127576+0000 PushNotifications[21497:6295793] [MC] System group container for path is /private/var/containers/Shared/SystemGroup/

2019-03-28 09:25:58.145576+0000 PushNotifications[21497:6295793] [MC] Reading from public effective user settings.

I am not sure what this means but it appears my didReceive( _:completionHander:) function is not being hit.

This is my NotificationViewController Code:

class NotificationViewController: UIViewController, UNNotificationContentExtension {

@IBOutlet var mapView: MKMapView!

override func viewDidLoad() {
    // Do any required interface initialization here.

func didReceive(_ notification: UNNotification) {

  let userInfo = notification.request.content.userInfo
  guard let latitude = userInfo["latitude"] as? CLLocationDistance,
  let longitude = userInfo["longitude"] as? CLLocationDistance,
    let radius = userInfo["radius"] as? CLLocationDistance else {
  let location = CLLocation(latitude: latitude, longitude: longitude)
  let region = MKCoordinateRegion(center: location.coordinate, latitudinalMeters: radius, longitudinalMeters: radius)
 mapView.setRegion(region, animated: false)

func didReceive( _ response: UNNotificationResponse,completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {

print("Processing Response")

defer { completion(.dismiss) }

guard let response = response as? UNTextInputNotificationResponse
  else {

let text = response.userText
print("The user responded with: \(text)")





@gargoyle Can you please help with this when you get a chance? Thank you - much appreciated! :]


It appears those error messages are a red herring as they are not really errors.

I found this article that is useful when it comes to debugging extensions. As it happens the extension code runs on a different process id to the app the print statements and breakpoints do not work in Xcode:

If you attach the debugger to the process I can see I am receiving he text response - it is just the print statements that do not display to the output window.

Others may find this useful :slightly_smiling_face:


@chris_shay You’re absolutely correct. The print messages won’t ever appear for the reason you specified. I thought I had mentioned that in the book when I spoke about debugging but apparently not. I’ll try to remember to explicitly call this out in the next release of the book!


If you want to see print statements in the console you can add them to a breakpoint in the extension code. Then after the process is attached then the log statements will appear. Be sure to select the Automatically continue after evaluating actions if you want it to behave just like a print(“stuff”) in the code. To see the value of an expression enclose it in @ like so: @radius@ 01%20AM


@gargoyle the above might make the next edition nicer


@tomtom It’ll definitely make it into the Fall release. Thanks for the great suggestion!