3

print statement does not work inside notification content extension, although I am able to modify the Label text and other fields, below is my code

class NotificationViewController: UIViewController, UNNotificationContentExtension {


@IBOutlet weak var label: UILabel!

override func viewDidLoad() {
    super.viewDidLoad()
    print("inside viewDidLoad of notificationViewController")
}

func didReceive(_ notification: UNNotification) {
    self.label?.text = notification.request.content.body
    print("inside didReceive of notificationViewController")

}

}

rahulk9
  • 795
  • 3
  • 10
  • 20

1 Answers1

18

The following steps pointed here worked for me:

After running the app that contains the extension,

  • Set your breakpoint in the extension
  • Select Debug / Attach to Process by PID or name
  • Enter the name of the extension target
  • Trigger the push notification
  • Breakpoints in extensions take forever to trigger. BE PATIENT, eventually your breakpoint will be hit

You will have to do this every time you restart your app via Xcode.

pedrohperalta
  • 206
  • 2
  • 4
  • hey my crashed upon receiving notification – Ian Aug 09 '18 at 10:12
  • https://stackoverflow.com/questions/49511005/cant-attach-debugger-to-unnotificationserviceextension just like this one, any thoughts ? – Ian Aug 09 '18 at 10:12
  • Any idea how long is "forever" in terms of triggering the breakpoint, 5 minutes, 10 minutes, or 1 hour? – CodeBrew Feb 22 '21 at 03:50