简体   繁体   中英

Extracting contact variables from profile page (phone #, email address, photo) to iOS Phonebook Contact List

I'd like to load information from user profiles in my app, into the iPhone Phonebook/Contact List.

My app has user profiles that contain various attributes about the person in which they're representing, such as their phone number, name, school, education level, email address, photo, summary of what they do, their interests etc.

What I'd like to be able to do, is for another user to be able to extract (with one click) contact attributes from this profile page so that it gets imported into the iPhone Contact List.

So for example, if I liked UserA, and I wanted to add her to my iPhone contact list, I would be able to click "Add to Contacts" which would then import all of UserA's relevant profile information (phone #, email address, street address, URL, photo, etc.) and create UserA as a new contact in my iPhone Phonebook.

Is this possible using iphone's abpeoplepicker api? If so, how do I go about executing this (where can I reference proper documentation), and what are the limitations/contraints/criteria in which this can be possible?

framework:

#import "AddressBook/AddressBook.h"

Code:

- (void) getLocalContacts
{
    ABAddressBookRef addressBook = ABAddressBookCreate( );
    CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
    CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );

    User *user;
    NSMutableArray *allContacts = [[NSMutableArray alloc] init];

    for ( int i = 0; i < nPeople; i++ )
    {
        ABRecordRef person = CFArrayGetValueAtIndex( allPeople, i );

        ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);

        if(ABMultiValueGetCount(emails) != 0)
        {
            user = [[User alloc] init];

            CFStringRef fName, lName;
            fName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
            lName  = ABRecordCopyValue(person, kABPersonLastNameProperty);

            CFStringRef email = ABMultiValueCopyValueAtIndex(emails, 0);


            NSData  *imgData = (NSData *)ABPersonCopyImageData(person);



            NSString *firstName = (NSString *) fName;
            NSString *lastName = (NSString *) lName;


            if (firstName.length == 0 && lastName.length != 0){
                user.userName = lastName;
            } 
            else if (firstName.length != 0 && lastName.length == 0){
                user.userName = firstName;
            }
            else if (firstName.length == 0 && lastName.length == 0){
                user.userName = @"";
            }
            else if (firstName.length != 0 && lastName.length != 0){
                user.userName = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
            }


            //user.firstName = (NSString *) firstName;
            user.lastName = @"";

            user.email = (NSString *) email;

            user.firstName = (NSString *) email;

            user.localImage = [UIImage imageWithData:imgData];

            [allContacts addObject:user];

            [user release];

        }
    }

    [DataManager sharedManager].allLocalUsers = allContacts;

    [self hideSpinner];

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM