从地址簿中呼叫联系人

时间:2011-07-05 09:33:04

标签: iphone ios contacts addressbook

我想以编程方式拨打电话号码,该电话号码在号码末尾包含#。由于Apple不接受这一点,我认为一种方法是在地址簿中添加联系人并使用它来拨打电话号码。所以我的问题是我如何链接我的应用程序中的联系人?

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

- (IBAction)addContact:(UIButton *)sender
{
    ABAddressBookRef addressBook = NULL;
    CFErrorRef error = NULL;

    switch (ABAddressBookGetAuthorizationStatus()) {
        case kABAuthorizationStatusAuthorized: {
            addressBook = ABAddressBookCreateWithOptions(NULL, &error);

            [self addAccountWithFirstName:self.firstNameField.text lastName:self.lastNameField.text inAddressBook:addressBook];

            if (addressBook != NULL) CFRelease(addressBook);
            break;
        }
        case kABAuthorizationStatusDenied: {
            NSLog(@"Access denied to address book");
            break;
        }
        case kABAuthorizationStatusNotDetermined: {
            addressBook = ABAddressBookCreateWithOptions(NULL, &error);
            ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef        error) {
                if (granted) {
                    NSLog(@"Access was granted");
                    [self addAccountWithFirstName:self.firstNameField.text lastName:self.lastNameField.text inAddressBook:addressBook];
                }
                else NSLog(@"Access was not granted");
                if (addressBook != NULL) CFRelease(addressBook);
            });
            break;
        }
        case kABAuthorizationStatusRestricted: {
            NSLog(@"access restricted to address book");
            break;
        }
    }
}## 
  

标题

##