0

我正在使用地址簿应用程序。在此,我创建了可以将联系人添加到通讯录并使用此人的记录更新本地通讯录中的联系人的方法。

但我面临的问题是,单击按钮时,我想打开所选人员的本地通讯录。我怎样才能做到这一点?

4

1 回答 1

0
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];
}  
于 2012-12-26T12:54:06.737 回答