Swift error when obtaining Contacts containers in Sierra beta?

I want to get the Contacts containers.


The following works on OSX 10.11:


import Contacts
let store = CNContactStore()
let containers = try store.containersMatchingPredicate(nil)


But on 10.12 Beta (16A304a) it gives an error (in XCode Playground):


Execution was interrupted, reason: EXC_BREAKPOINT (code=EXC_1386_BPT, subcode=0x0)


Both in XCode 7.3.1 and XCode 8.0 Beta.

Any suggestions?


Note: additional difference between the 10.11 system and 10.12 systems:

the 10.11 system has 2 containers (local and iCloud)

the 10.12 systems have Exchange containers as well (even though this Exchange account is not enabled for contacts)

Hello wvkg,


did you find a solution in the meantime?

I'm having the same issue. After upgrading to 10.12 containersMatchingPredicate isn't delivering any container anymore.

Just "On my Mac" is returning. No iCloud, no CardDav Containers.

With the latest Sierra releases, trying to fetch carddav Contacts fails for me, too. Fetching local contacts works.


Just found https://github.com/keith/contacts-cli/issues/3

but do not yet know, if this changes anything. I do not use an app for accessing contacts but instead use a shellscript with swift 3 with the Contacts framework.

Stephane204 answer solution worked for me, here: https://forums.developer.apple.com/thread/64274


"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)."

Swift error when obtaining Contacts containers in Sierra beta?
 
 
Q