Search code examples
contactscloudkit

Can you use CloudKit to access a user's contacts from a React/Django project?


I have a react/django project and we need to somehow access the contacts of our users. I was told to look into CloudKit's API in order to take care of this, however there seems to be no real information in their docs or in my Google searches on using this API to specifically access a user's contacts.

I am open to other suggestions as well. The ideal would be to access their contacts initially and then every so often compare their contacts to our list to see if any have been added.


Solution

  • You cannot access this data from a third-party app via a CloudKit API.

    While Apple does store a user's contacts on CloudKit, they do so under these conditions:

    • The user opts-in to sync their contacts with iCloud (this isn't required for iOS users; they can be on-device only, or sync with another service like Google).
    • The contacts Apple stores on CloudKit are in a container that is private to Apple.

    When you use CloudKit as a developer, you are creating a container for your app. You can only access data in containers you create.

    Here's what you would have to do:

    1. Create an iOS or macOS app that requests/manages access to the user's contacts.
    2. Add the Contacts entitlement to your target in Xcode: Signing & Capabilities > App Sandbox > App Data > Contacts
    3. Use Apple's Contacts framework to access contact data using Swift in your iOS/macOS app.
    4. Once you have the data in your Swift app, communicate with your Django API to do what you need to.

    One last thing. If you choose to go this route, you will have to reveal in your app privacy disclosures (in App Store Connect) what you are doing with the users' data.