Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从iphone获取所有通讯簿联系人_Iphone_Addressbook - Fatal编程技术网

如何从iphone获取所有通讯簿联系人

如何从iphone获取所有通讯簿联系人,iphone,addressbook,Iphone,Addressbook,我不熟悉iphone。我被困在我的项目中,无法将iphone设备中的所有通讯录联系人(姓名和电子邮件)放入我在项目中创建的表视图中。我怎样才能做到这一点?使用addressbook api来做到这一点。看到我的答案了吗 如需了解更多详细信息,请获取apple文档。使用addressbook api完成此操作。看到我的答案了吗 如需了解更多详细信息,请参阅苹果的文档。NSMutableArray*contactsArray=[NSMutableArray new]; //打开默认通讯簿。 AB

我不熟悉iphone。我被困在我的项目中,无法将iphone设备中的所有通讯录联系人(姓名和电子邮件)放入我在项目中创建的表视图中。我怎样才能做到这一点?

使用addressbook api来做到这一点。看到我的答案了吗


如需了解更多详细信息,请获取apple文档。

使用addressbook api完成此操作。看到我的答案了吗

如需了解更多详细信息,请参阅苹果的文档。

NSMutableArray*contactsArray=[NSMutableArray new];
//打开默认通讯簿。
ABAddressBookRef m_addressbook=ABAddressBookCreate();
如果(!m_地址簿)
{
NSLog(@“期初通讯簿”);
}
CFArrayRef allPeople=abAddressBookCopyArrayFallPeople(m_addressbook);
CFIndex nPeople=ABAddressBookGetPersonCount(m_addressbook);
for(int i=0;i
联系人阵列中保存的所有联系人数据。然后您可以根据需要使用此阵列。

NSMutableArray*contactsArray=[NSMutableArray new];
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>

-(void)viewWillAppear:(BOOL)animated{

    NSMutableArray* contactsArray = [NSMutableArray new];

    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* tempContactDic = [NSMutableDictionary new];
        ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);
        NSLog(@"tempContactDic ios a ==%@",tempContactDic);
       CFStringRef firstName, lastName;
        firstName = (__bridge CFStringRef)((__bridge UILabel *)(ABRecordCopyValue(ref, kABPersonFirstNameProperty)));
        lastName  = (__bridge CFStringRef)((__bridge UILabel *)(ABRecordCopyValue(ref, kABPersonLastNameProperty)));
      //  [tempContactDic setValue:name forKey:@"name"];
        //fetch email id
        NSString *strEmail;
        ABMultiValueRef email = ABRecordCopyValue(ref, kABPersonEmailProperty);
        CFStringRef tempEmailref = ABMultiValueCopyValueAtIndex(email, 0);
        strEmail = (__bridge  NSString *)tempEmailref;

        [tempContactDic setValue:strEmail forKey:@"email"];

        [contactsArray addObject:tempContactDic];

    }

}
-(IBAction)getcontactlist:(id)sender{

         [self getContact];
}

-(IBAction)getContact {
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;
    [self presentViewController:picker animated:YES completion:nil];

}

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {

    firstName.text = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
    lastName.text = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
    ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
    number.text = (__bridge NSString*)ABMultiValueCopyValueAtIndex(multi, 0);
    return YES;
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
    return NO;
}
//打开默认通讯簿。 ABAddressBookRef m_addressbook=ABAddressBookCreate(); 如果(!m_地址簿) { NSLog(@“期初通讯簿”); } CFArrayRef allPeople=abAddressBookCopyArrayFallPeople(m_addressbook); CFIndex nPeople=ABAddressBookGetPersonCount(m_addressbook); for(int i=0;i
联系人阵列中保存的所有联系人数据。然后您可以根据需要使用此阵列。

\import
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>

-(void)viewWillAppear:(BOOL)animated{

    NSMutableArray* contactsArray = [NSMutableArray new];

    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* tempContactDic = [NSMutableDictionary new];
        ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);
        NSLog(@"tempContactDic ios a ==%@",tempContactDic);
       CFStringRef firstName, lastName;
        firstName = (__bridge CFStringRef)((__bridge UILabel *)(ABRecordCopyValue(ref, kABPersonFirstNameProperty)));
        lastName  = (__bridge CFStringRef)((__bridge UILabel *)(ABRecordCopyValue(ref, kABPersonLastNameProperty)));
      //  [tempContactDic setValue:name forKey:@"name"];
        //fetch email id
        NSString *strEmail;
        ABMultiValueRef email = ABRecordCopyValue(ref, kABPersonEmailProperty);
        CFStringRef tempEmailref = ABMultiValueCopyValueAtIndex(email, 0);
        strEmail = (__bridge  NSString *)tempEmailref;

        [tempContactDic setValue:strEmail forKey:@"email"];

        [contactsArray addObject:tempContactDic];

    }

}
-(IBAction)getcontactlist:(id)sender{

         [self getContact];
}

-(IBAction)getContact {
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;
    [self presentViewController:picker animated:YES completion:nil];

}

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {

    firstName.text = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
    lastName.text = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
    ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
    number.text = (__bridge NSString*)ABMultiValueCopyValueAtIndex(multi, 0);
    return YES;
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
    return NO;
}
#进口 -(无效)视图将显示:(BOOL)动画{ NSMutableArray*contactsArray=[NSMutableArray新建]; ABAddressBookRef m_addressbook=ABAddressBookCreate(); 如果(!m_地址簿) { NSLog(@“期初通讯簿”); } CFArrayRef allPeople=abAddressBookCopyArrayFallPeople(m_addressbook); CFIndex nPeople=ABAddressBookGetPersonCount(m_addressbook); for(int i=0;i
此代码对我来说运行良好…

#导入
#进口
-(无效)视图将显示:(BOOL)动画{
NSMutableArray*contactsArray=[NSMutableArray新建];
ABAddressBookRef m_addressbook=ABAddressBookCreate();
如果(!m_地址簿)
{
NSLog(@“期初通讯簿”);
}
CFArrayRef allPeople=abAddressBookCopyArrayFallPeople(m_addressbook);
CFIndex nPeople=ABAddressBookGetPersonCount(m_addressbook);
for(int i=0;i