Search code examples
icloudcloudkit

Accessing user profile picture from iCloud account


I'm attempting to pull a user's profile picture from their iCloud account. I'm using CloudKit and am verifying the user has an iCloud account as well as requesting discoverability permissions. I'm not sure this is possible but if it is I'd like to know how. Here is the relevant code:

To verify iCloud account:

[[CKContainer defaultContainer] accountStatusWithCompletionHandler:^(CKAccountStatus accountStatus, NSError *error) {
    if (accountStatus == CKAccountStatusAvailable)
    {
        self.shouldLogin = YES;
    }
    else
    {
        self.shouldLogin = NO;
    }
}];

To pull their profile image out of their iCloud account:

    [[CKContainer defaultContainer] requestApplicationPermission:CKApplicationPermissionUserDiscoverability completionHandler:^(CKApplicationPermissionStatus applicationPermissionStatus, NSError * _Nullable error) {
    if (applicationPermissionStatus == CKApplicationPermissionStatusGranted)
    {
        [[CKContainer defaultContainer] discoverUserInfoWithUserRecordID:self.dataStore.user.userID completionHandler:^(CKDiscoveredUserInfo * _Nullable userInfo, NSError * _Nullable error) {
            NSData *imageData = userInfo.displayContact.imageData;
            UIImage *profileImage = [UIImage imageWithData:imageData];
            self.profileImageView.image = profileImage;
        }];
    }
}];

Solution

  • You can not get more than an unique ID plus the first and last name of an iCloud user. If you want more information, then you have to ask all users for that data.