swift Swift - CloudKit用户ID和信息

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift Swift - CloudKit用户ID和信息相关的知识,希望对你有一定的参考价值。

See: http://www.techotopia.com/index.php/An_Introduction_to_CloudKit_Data_Storage_on_iOS_8

Within the scope of an application’s cloud container, each user has a unique, application specific iCloud user ID and a user info record where the user ID is used as the record ID for the user’s info record.
The record ID of the current user’s info record can be obtained via a call to the fetchUserRecordID(completionHandler:) method of the container instance. Once the record ID has been obtained, this can be used to fetch the user’s record from the cloud database:
container.fetchUserRecordID(completionHandler: {recordID,    
        error in
            if let err = error {
                // Failed to get record ID
            } else {
		   // Success – fetch the user’s record here
	      }
The record is of type CKRecordTypeUserRecord and is initially empty. Once fetched, it can be used to store data in the same way as any other CloudKit record.
CloudKit can also be used to perform user discovery. This allows the application to obtain an array of the users in the current user’s address book who have also used the app. In order for the user’s information to be provided, the user must have run the app and opted in to provide the information. User discovery is performed via a call to the discoverAllIdentities(completionHandler:) method of the container instance.
The discovered data is provided in the form of an array of CKApplicationUserInfo objects which contain the user’s iCloud ID, first name and last name. The following code fragment, for example, performs a user discovery operation and outputs to the console the first and last names of any users that meet the requirements for discoverability:
container.discoverAllIdentities(completionHandler: (
     {users, error in

        if let err = error {
            print("discovery failed %@", 
                   err.localizedDescription)
        } else {

            for userInfo in user {
                let userRecordID = userInfo.userRecordID
                print("First Name = %@", userInfo.firstName)
                print("Last Name = %@", userInfo.lastName)
            }
        }
    })

以上是关于swift Swift - CloudKit用户ID和信息的主要内容,如果未能解决你的问题,请参考以下文章

swift Swift - CloudKit - 获取用户ID

swift Swift - CloudKit - 推送通知

swift Swift - CloudKit共享

swift Swift - CloudKit - 维护本地缓存

swift Swift - CloudKit - 部署架构

swift Swift - CloudKit订阅 - 5