Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.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
将IOS通讯簿链接到应用程序_Ios_Iphone_Objective C_Addressbook_Ios7.1 - Fatal编程技术网

将IOS通讯簿链接到应用程序

将IOS通讯簿链接到应用程序,ios,iphone,objective-c,addressbook,ios7.1,Ios,Iphone,Objective C,Addressbook,Ios7.1,我想在我的应用程序中链接地址簿视图控制器,我已经在互联网上搜索并在apple developer guide中找到了,但它们显示了当单击按钮时如何打开联系人选择器,我不希望联系人选择器成为我故事板中的视图控制器。我想我可以通过制作一个定制的tableviewcontroller并从通讯录中获取信息来实现这一点,或者我可以直接实现吗?这应该可以帮助您开始: 另外,不要忘记导入并链接到以下框架: #import <AddressBookUI/AddressBookUI.h> #impor

我想在我的应用程序中链接地址簿视图控制器,我已经在互联网上搜索并在apple developer guide中找到了,但它们显示了当单击按钮时如何打开联系人选择器,我不希望联系人选择器成为我故事板中的视图控制器。我想我可以通过制作一个定制的tableviewcontroller并从通讯录中获取信息来实现这一点,或者我可以直接实现吗?

这应该可以帮助您开始:

另外,不要忘记导入并链接到以下框架:

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

您不能期望复制和粘贴代码并期望它工作。你需要链接和导入我在上面列出的框架我添加了它们。。。错误是找不到(findcontacts)选择器?抱歉,我没有复制所有代码。。。现在没有发现错误。。。但它看不到我的通讯录,这是不应该的。您的工作是使用我提供的代码,从
ABRecordRef
中提取您需要的NSString,我必须在那里调用(self-requestPermissionForContacts];)
- (void)requestPermissionForContacts
{
    ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

    if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined)
    {
        ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error)
        {
            if (granted)
            {
                dispatch_async(dispatch_get_main_queue(), ^
                {
                    [self findContacts];
                });
            }
            else
            {
                dispatch_async(dispatch_get_main_queue(), ^
                {
                    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Find Contacts" message:@"To allow us to find your contacts, you will need to go to the Settings app > Privacy > Contacts, and set your app name here to On." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
                });
            }
        });
    }
    else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized)
    {
        [self findContacts];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Find Contacts" message:@"To allow us to find your contacts, you will need to go to the Settings app > Privacy > Contacts, and set your app name here to On." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
}

- (void)findContacts
{
    ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

    CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBookRef);

    CFIndex numberOfPeople = CFArrayGetCount(people);

    if (numberOfPeople > 0)
    {
        NSMutableArray *mutableEmailsArray = [[NSMutableArray alloc]init];
        NSMutableArray *mutablePhonesArray = [[NSMutableArray alloc]init];

        for (int i = 0; i < numberOfPeople; i++)
        {
            ABRecordRef ref = CFArrayGetValueAtIndex(people, i);

            ABMultiValueRef emails = (__bridge ABMultiValueRef)((__bridge NSString*)ABRecordCopyValue(ref, kABPersonEmailProperty));

            ABMultiValueRef phones = (__bridge ABMultiValueRef)((__bridge NSString*)ABRecordCopyValue(ref, kABPersonPhoneProperty));

            if (ABMultiValueGetCount(emails) > 0)
            {
                [mutableEmailsArray addObjectsFromArray:((__bridge NSArray *)(ABMultiValueCopyArrayOfAllValues(emails)))];
            }

            if (ABMultiValueGetCount(phones) > 0)
            {
                [mutablePhonesArray addObjectsFromArray:((__bridge NSArray *)(ABMultiValueCopyArrayOfAllValues(phones)))];
            }
        }

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:[NSString stringWithFormat:@"%ld Emails %ld Phone Numbers", (unsigned long)mutableEmailsArray.count, (unsigned long)mutablePhonesArray.count] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"No Contacts" message:@"No contacts were found on your device." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
}