Contacts CNContactStore results in accountsWithAccountType: error

Hello,


After upgrading to macOS Sierra and Xcode 8, I receive the following errors when launching my app:


[error] warning: dynamic accessors failed to find @property implementation for 'uniqueId' for entity ABCDInfo while resolving selector 'uniqueId' on class 'ABCDInfo'. Did you remember to declare it @dynamic or @synthesized in the @implementation ?

[error] warning: dynamic accessors failed to find @property implementation for 'serialNumber' for entity ABCDAddressBookSource while resolving selector 'serialNumber' on class 'ABCDAddressBookSource'. Did you remember to declare it @dynamic or @synthesized in the @implementation ?


(And several more along the same lines.)


I figure this is because I use the AddressBook framework and that I had probably better update to use the Contacts framework instead. However, I can't get the Contacts framework working. Here is my code trying to create a CNContactStore object and get the "Me" card contact:


CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];

    NSArray *keys = @[CNContactIdentifierKey,
                      CNContactGivenNameKey,
                      CNContactFamilyNameKey,
                      CNContactPostalAddressesKey,
                      CNContactPhoneNumbersKey,
                      CNContactEmailAddressesKey,
                      CNContactNoteKey];

    if (status == CNAuthorizationStatusAuthorized)
    {
        NSLog (@"1a");
  
        CNContactStore *contactStore = [[CNContactStore alloc] init];
  
        NSLog (@"2a: %@", contactStore);
  
        CNContact *contact = [contactStore unifiedMeContactWithKeysToFetch:keys error:nil];
  
        NSLog (@"%@ %@", contact.givenName, contact.familyName);
  
    }
    else if (status == CNAuthorizationStatusNotDetermined)
    {
        NSLog (@"1b");
  
        CNContactStore *contactStore = [[CNContactStore alloc] init];
  
        [contactStore requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
            if(granted){
          
          
                NSLog (@"2b: %@", contactStore);
          
                CNContact *contact = [contactStore unifiedMeContactWithKeysToFetch:keys error:nil];
          
                NSLog (@"%@ %@", contact.givenName, contact.familyName);
            }
        }];
    }


When I run this code, when trying to create the CNContactStore object, I receive the following error on the Console:


_block_invoke_2 (208) "Error returned from daemon: <private>"

_block_invoke_2 (208) "Error returned from daemon: <private>"


What does this mean? This error occurs twice between the 1a and 2a logs above.


Nonetheless, the 2a log shows that a CNDataMapperContactStore object is created. But calling -unifiedMeContactWithKeysToFetch on it results in a nil contact being returned, with the following error:


Error Domain=CNErrorDomain Code=200 "Updated Record Does Not Exist"


And yet I have a "me" contact in Contacts on my machine (a contact card with the little user silhouette icon next to it).


If I then try to enumerate the contactStore, I just receive a single CNContact object that is blank.


On top of this, I'm asked to authorise the app to use Contacts every time I launch it.


And, finally, when I enumerate the contactStore, I receive exactly the same errors on the Console as I did when using AddressBook anyway, which probably means my attempts to update to Contacts are pointless anyway. 🙂


[error] warning: dynamic accessors failed to find @property implementation for 'uniqueId' for entity ABCDPhoneNumber while resolving selector 'uniqueId' on class 'ABCDPhoneNumber'. Did you remember to declare it @dynamic or @synthesized in the @implementation ?

[error] warning: dynamic accessors failed to find @property implementation for 'label' for entity ABCDPhoneNumber while resolving selector 'label' on class 'ABCDPhoneNumber'. Did you remember to declare it @dynamic or @synthesized in the @implementation ?


Has anybody encountered errors like this? Am I doing to something mindnumbingly silly somewhere?


Thanks!

I have a similar problem with my app since upgrading to Sierra/Xcode8. The only thing I can add is that the full error message in my case is [ACAccountStore accountsWithAccountType:]_block_invoke_2 (208) "Error returned from daemon: <private>" Seems as if some new step is required to access the store.

I also have this exact same problem too.

My app was perfectly working, fetching images of contacts with XCode 7. I switched to Sierra/XCode 8, and suddenly everything is broken.


I was already using the CNContact framework.


This same code works perfectly with iOS 9 and iOS 10.


I also checked that the app that does not work on macOS Sierra (10.12) is working fine on mac OS 10.11 (still complied with XCode 8). So the problem is definitely located in macOS 10.12

I found a solution !!!


Apple has answered my radar with the following statement : "Contacts now requires that anyone using it be codesigned with the uses-contacts entitlement."


So what I did is that I sandboxed my app, and granted the "Contacts access" entitlement. Everything works fine again. I mean here that I can access the Contacts information.

However, the warnings are still logged, but this is linked to another bug of XCode 8 that logs so many things uselessly.


It seems Apple will no longer accept non sandboxed app to access the Contacts (or location or calendar).

Thank you Stephane204. It worked for me.

Note, I was also able to get this to work without requiring sandboxing.


I granted the contacts entitlement, but then edited the entitlements file and set sandbox to false:


<dict>
        <key>com.apple.security.app-sandbox</key>
        <false/>
        <key>com.apple.security.personal-information.addressbook</key>
        <true/>
        <key>com.apple.security.personal-information.calendars</key>
        <true/>
</dict>



I verified using Activity Monitor that my app was not sandboxed, but was still able to access the address book.

Can someone from Apple reply whether it is considered "safe" to use approach declared by @pexlabs?


I have the same issue accessing Contacts framework under macOS 10.12 from non-sandboxed app.

Without addressbook entitlement Contacts framework works on some systems while not working on others.

With addressbook entitlement (and app-sandbox=false inside entitlements) it seems to work everywhere.


But, because this entitlement is under App Sandbox group, that either means:

a) That non-sandbox apps can't "officially" access Contacts at all under 10.12;

b) Non-sandbox app just need to include `contacts` entitlement into their entitlements plist and leave App Sandbox = FALSE which is undocumented "feature".

For the case `b`, it's not so trustworthy as this behaviour is unknown. We don't know what will happen on most of user systems, we only can test it on ours and hope for the best.

Contacts CNContactStore results in accountsWithAccountType: error
 
 
Q