简体   繁体   English

将个人资料页面(电话号码,电子邮件地址,照片)中的联系人变量提取到iOS电话簿联系人列表中

[英]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. 我想将应用程序中用户配置文件中的信息加载到iPhone电话簿/联系人列表中。

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. 我想要做的是让另一个用户能够从此配置文件页面中提取(单击一下)联系人属性,以便将其导入到iPhone联系人列表中。

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. 因此,例如,如果我喜欢UserA,并且想将她添加到我的iPhone联系人列表中,则可以单击“添加到联系人”,然后导入所有UserA的相关个人资料信息(电话号码,电子邮件地址,街道地址,URL,照片等),并在我的iPhone电话簿中将UserA创建为新联系人。

Is this possible using iphone's abpeoplepicker api? 使用iPhone的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];

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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