如何在IOS 6中访问iPhone的联系人 [英] How to acess contacts of iPhone in IOS 6

查看:84
本文介绍了如何在IOS 6中访问iPhone的联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中显示联系人和联系人的详细信息。联系人列表和选择该联系人的任何联系人详细信息后,将使用地址簿显示在下一页上。我正在研究IOS 6.
提前致谢。

I want to show contacts and details of contacts in my application.List of contacts and after selecting any contact details of that contact will show on next page using addressbook. I am working on IOS 6. Thanks in advance.

推荐答案

以下代码用于检索联系方式。

Following code for retrieving contact details.

- (void)viewDidLoad {
    [super viewDidLoad];
    contactList=[[NSMutableArray alloc] init];
    ABAddressBookRef m_addressbook = ABAddressBookCreate();

    if (!m_addressbook) {
        NSLog(@"opening address book");
    }

    CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);
    CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);

    for (int i=0;i < nPeople;i++) { 
        NSMutableDictionary *dOfPerson=[NSMutableDictionary dictionary];

        ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);

        //For username and surname
        ABMultiValueRef phones =(NSString*)ABRecordCopyValue(ref, kABPersonPhoneProperty);
        CFStringRef firstName, lastName;
        firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
        lastName  = ABRecordCopyValue(ref, kABPersonLastNameProperty);
        [dOfPerson setObject:[NSString stringWithFormat:@"%@ %@", firstName, lastName] forKey:@"name"];

        //For Email ids
        ABMutableMultiValueRef eMail  = ABRecordCopyValue(ref, kABPersonEmailProperty);
        if(ABMultiValueGetCount(eMail) > 0) {
            [dOfPerson setObject:(NSString *)ABMultiValueCopyValueAtIndex(eMail, 0) forKey:@"email"];

        }

        //For Phone number
        NSString* mobileLabel;
        for(CFIndex i = 0; i < ABMultiValueGetCount(phones); i++) {
            mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
            if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel])
            {
                [dOfPerson setObject:(NSString*)ABMultiValueCopyValueAtIndex(phones, i) forKey:@"Phone"];
            }
            else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhoneIPhoneLabel])
            {
                [dOfPerson setObject:(NSString*)ABMultiValueCopyValueAtIndex(phones, i) forKey:@"Phone"];
                break ;
            }

        [contactList addObject:dOfPerson];
        CFRelease(ref);
        CFRelease(firstName);
        CFRelease(lastName);
    }
    NSLog(@"array is %@",contactList);
    }
}

这篇关于如何在IOS 6中访问iPhone的联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆