Chapter 8 Handling Common Scenarios error tapping notification when app is in background

When I try tapping the notification when the app is on the background and redirect to BeachView I get this error:

I used the code provided in the book:

func userNotificationCenter(
  _ center: UNUserNotificationCenter,
  didReceive response: UNNotificationResponse
) async {
  if response.notification.request.content.userInfo["beach"] != nil {
    // In a real app you'd likely pull a URL from the beach data
    // and use that image.
    await MainActor.run {
      isBeachViewActive = true
    }
  }
}

The only way that I got it working is by putting that MainActor call inside a Task. Any idea why is this happening?

Please help, @gargoyle . Thanks!

I’m not sure what’s going on there. My only guess is you have something else which is trying to trigger a UI update. Putting that await into a task shouldn’t make any difference as you’re already in an async method. Sorry :frowning:

1 Like