Skip to content

Instantly share code, notes, and snippets.

@benjaminsnorris
Created November 22, 2014 02:14
Show Gist options
  • Save benjaminsnorris/268577e2f20f794d6747 to your computer and use it in GitHub Desktop.
Save benjaminsnorris/268577e2f20f794d6747 to your computer and use it in GitHub Desktop.
Updating User from Contacts
- (void)updateUserWithContactInfo {
PFUser *currentUser = [PFUser currentUser];
NSString *name = currentUser[nameKey];
NSArray *people = (NSArray *)CFBridgingRelease(ABAddressBookCopyPeopleWithName(ABAddressBookCreateWithOptions(NULL, NULL), (__bridge CFStringRef)(name)));
if (people != nil && people.count > 0) {
ABRecordRef person = (__bridge ABRecordRef)[people objectAtIndex:0];
NSData *photoData = CFBridgingRelease(ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail));
NSString *firstName = CFBridgingRelease(ABRecordCopyValue(person, kABPersonFirstNameProperty));
NSString *lastName = CFBridgingRelease(ABRecordCopyValue(person, kABPersonLastNameProperty));
if (photoData != nil) {
PFFile *photoFile = [PFFile fileWithData:photoData];
currentUser[photoKey] = photoFile;
}
currentUser[firstNameKey] = firstName;
currentUser[lastNameKey] = lastName;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment