Created
November 22, 2014 02:14
-
-
Save benjaminsnorris/268577e2f20f794d6747 to your computer and use it in GitHub Desktop.
Updating User from Contacts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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