2

Attempting to create a local notification fails with the following error:

Adding notification request failed with error: Error
Domain=NSCocoaErrorDomain Code=4097 "connection to service named
com.apple.usernotifications.usernotificationservice" UserInfo=
{NSDebugDescription=connection to service named 
com.apple.usernotifications.usernotificationservice}

What does that mean?

Matt
  • 4,261
  • 4
  • 39
  • 60

3 Answers3

9

This is caused by attempting to pass a URL from objectID.uriRepresentation() in userInfo of the notification.

It is necessary to store objectID.uriRepresentation().absoluteString instead.

When the notification is handled, the objectID can be recovered by:

persistentStoreCoordinator
    .managedObjectID(forURIRepresentation: URL(string: uri))
Matt
  • 4,261
  • 4
  • 39
  • 60
  • Thanks. Got the same error message, and following your answer, I found out that I was setting a non-property list type in the notification's `UserInfo`. I have removed it and it started to work :) – shbedev Jan 02 '20 at 13:18
1

I faced the issue by trying to add userInfo with a URL type value. Fixed by changed the URL to String.

You may check whether your input value is String Value. If not, make it as a string could fix this issue.

Jerome Li
  • 1,492
  • 14
  • 20
1

I got this by including a NSUUID/UUID in a dictionary, switching to the string representation has stopped the error being reported!

CMash
  • 1,987
  • 22
  • 35