NSCocoaErrorDomain Code=134092 When Updating ContactsError, and Error "Attempt to read notes by an unentitled app" while I am not request for notes

Hi, I'm writing a command line program with Swift Package Manager that uses Contacts API to automatically add phonetic names for the contacts. However, I found I was unable to do so for contacts that has notes. First, when I was trying to enumerate the contacts, there is a strange error output:

2023-01-22 18:58:36.085525+0800 PhoneticNames[18591:98356] [core] Attempted to register account monitor for types client is not authorized to access: {(
    "com.apple.account.CardDAV",
    "com.apple.account.Exchange",
    "com.apple.account.LDAP"
)}
2023-01-22 18:58:36.085580+0800 PhoneticNames[18591:98356] [accounts] CNAccountCollectionUpdateWatcher 0x6000003ccc40: Store registration failed: Error Domain=com.apple.accounts Code=7 "(null)"
2023-01-22 18:58:36.085606+0800 PhoneticNames[18591:98356] [accounts] CNAccountCollectionUpdateWatcher 0x6000003ccc40: Update event received, but store registration failed. This event will be handled, but the behavior is undefined.
2023-01-22 18:58:36.136236+0800 PhoneticNames[18591:98344] [api] Attempt to read notes by an unentitled app

According to this document, I need to add the notes entitlement only if I was requesting the note field with CNContactNoteKey. However, I was not requesting it and I still get that "Attempt to read notes by an unentitled app" error.

Here is my code for enumerating the contacts:

let keys: [CNKeyDescriptor] = [CNContactFormatter.descriptorForRequiredKeys(for: .fullName),
                               CNContactFormatter.descriptorForRequiredKeys(for: .phoneticFullName)]
let fetchRequest = CNContactFetchRequest(keysToFetch: keys as [CNKeyDescriptor])
fetchRequest.mutableObjects = true
do {
    try store.enumerateContacts(with: fetchRequest) { (contact, stop) in
        contacts.append(contact.mutableCopy() as! CNMutableContact)
    }
} catch {
    print("unable to list contacts. \(error)")
}

And this is how I update the contacts later:

let saveRequest = CNSaveRequest()
contact.phoneticFamilyName = phoneticFamilyName
contact.phoneticMiddleName = phoneticMiddleName
contact.phoneticGivenName = phoneticGivenName
saveRequest.update(contact)
do {
    try store.execute(saveRequest)
} catch {
    print("Fail to execute store request: \(error)")
}

This code works as expected for contacts without the note field. But for contact with a non-empty note field, the saveRequest fails and outputs the following error:

2023-01-22 18:58:36.197026+0800 PhoneticNames[18591:98344] [error] error: Unhandled error occurred during faulting: Error Domain=NSCocoaErrorDomain Code=134092 "(null)" ({
})
CoreData: error: Unhandled error occurred during faulting: Error Domain=NSCocoaErrorDomain Code=134092 "(null)" ({
})
2023-01-22 18:58:36.201308+0800 PhoneticNames[18591:98344] [plugin] CDX_AB_GetGroupCollectionPath: nil group
2023-01-22 18:58:36.201353+0800 PhoneticNames[18591:98344] [plugin] CDX_AB_GetGroupCollectionPath: nil group 

In debugging mode inside Xcode, the contact will still be updated with phoetic names. But if I execute the compiled release binary in terminal, the output will be:

CoreData: error: Unhandled error occurred during faulting: Error Domain=NSCocoaErrorDomain Code=134092 "(null)" ({
})
Fail to execute store request: Error Domain=NSCocoaErrorDomain Code=134092 "(null)" UserInfo={NSUnderlyingException=Unhandled error (NSCocoaErrorDomain, 134092) occurred during faulting and was thrown: Error Domain=NSCocoaErrorDomain Code=134092 "(null)", NSUnderlyingError=0x600002ee05d0 {Error Domain=NSCocoaErrorDomain Code=134092 "(null)"}}

The contact will not be updated in this case.

I looked for all the documents but couldn't find anything about NSCocoaErrorDomain Code 134092. Can you please give me some clues about the aforementioned behaviors?

I have a similar issue, I think. I have a macOS and iOS app which share the same code. Both make a call to CNContactStore().unifiedContact(withIdentifier, keysToFetch). However, th iOS call takes a small fraction of the time for a given contact - 0.005s compared to 0.35s! The console in the Mac has the message [api] Attempt to read notes by an unentitled app I am not trying to read a note from the contact. The contact actually has a blank note.

So it looks like the macOS mistakenly thinks I am trying to access a note, and that this cause a delay in the routine.

I have the same issue. My code looks like this:

let predicate = CNContact.predicateForContacts(matchingEmailAddress: emailAddress)
let keysToFetch = [CNContactImageDataKey, CNContactThumbnailImageDataKey] as [CNKeyDescriptor]

if let contacts = try? CNContactStore().unifiedContacts(matching: predicate, keysToFetch: keysToFetch) {
	// ...
}

where I get the following errors:

Attempted to register account monitor for types client is not authorized to access: {(
    "com.apple.account.CardDAV",
    "com.apple.account.Exchange",
    "com.apple.account.LDAP"
)}
CNAccountCollectionUpdateWatcher 0x600004280e80: Store registration failed: Error Domain=com.apple.accounts Code=7 "(null)"
CNAccountCollectionUpdateWatcher 0x600004280e80: Update event received, but store registration failed. This event will be handled, but the behavior is undefined.
Attempt to read notes by an unentitled app

on macOS 14.5 (23F79).

I can ignore the errors in the console, which is not ideal, but my main issue with these errors is that they trigger the “All Runtime Issues” breakpoint.

NSCocoaErrorDomain Code=134092 When Updating ContactsError, and Error "Attempt to read notes by an unentitled app" while I am not request for notes
 
 
Q