Search code examples
iosobjective-ccloudkit

Creating a User record based on currently logged in Apple ID


Using Objective-C is there a way I can create a new user to an app based on their apple ID automatically. I would be using this in conjunction with CloudKit In order to create and auth users without creating a whole 'login' and 'sign up' view


Solution

  • CloudKit gives you this out of the box. CKContainer can return a user record of the currently signed in user on the device, and it will even have a stable identifier (recordID) that you can use to authenticate and identify the same user across devices.

    Since the user recordID is scoped to just your container, and by default the developer won't get any user details from the Apple ID (unless discoverability has been opted in to), there is no explicit login or UI necessary in the client. It's all just seamless from a user experience perspective.

    You'll find more documentation on how to fetch the user record at: https://developer.apple.com/library/ios/documentation/CloudKit/Reference/CKContainer_class/index.html#//apple_ref/occ/instm/CKContainer/fetchUserRecordIDWithCompletionHandler: