Cloudkit: How to Access Main User's Attributes

cloudkit: how to access main user's attributes?

You first have to find out what the current loged in userId is. You can do that by executing the fetchUserRecordIDWithCompletionHandler method on the container. Then you can get more (currently only first and last name) information by executing the discoverUserInfoWithUserRecordID on that container.

You could extend the Users table with extra custom fields, but I would not advice doing that. The Users table is a special system table with some limitations. It would be better to create a separate recordType with the user settings. Just add a CKReference to the users table for easy access.

You also have to be aware that a user could log out and log in with a different iCloud account during the operation of your app. You could capture this by executing the code below right after your application start. Of course you have to implement your own logic where you see the NSLog

    var ubiquityIdentityDidChangeNotificationToken = NSNotificationCenter.defaultCenter().addObserverForName(NSUbiquityIdentityDidChangeNotification, object: nil, queue: nil) { _ in
NSLog("The user’s iCloud login changed: should refresh all user data.")
}

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

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.

cloudkit enter userID as reference of a new record (in code)

If your user field is set up as a CKReference field, then you should set it like this:

daMainUser.setObject(CKReference(recordID: userRecordID, action: CKReferenceAction.None), forKey: "user")

In your case you do not have to create a recordID because you already have it. Otherwise you had to create it with something like:

var recordID = CKRecordID(recordName: userRecordID.recordName)

How to retrieve AppleID of logged in user via CloudKit?

You cannot retrieve the current user's email address - you're going to have to ask for it outside of CloudKit. This is a privacy thing. You're supposed to use the UserRecordId to uniquely identify users.

You can, however, search for other users if you already know their email address with CKDiscoverUserInfosOperation.

CloudKit in order to shared data between users

This could work for you, yes.

CloudKit provides complementary services for managing the transfer of
data to and from iCloud servers.

Reference



Related Topics



Leave a reply



Submit