开发者

Calling a contact from the Address Book

开发者 https://www.devze.com 2023-03-17 20:57 出处:网络
I want to call programmatically a phone number that contains a # at the end of the number. Since Apple doesn\'t accept this , I thought that a way would be to add a contact in the address book and use

I want to call programmatically a phone number that contains a # at the end of the number. Since Apple doesn't accept this , I thought that a way would be to add a contact in the address book and use that to call numbers. So my question is how can I link c开发者_运维问答ontacts from my app?


You might want to take a look at the address book programming guide: http://developer.apple.com/library/ios/#documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Introduction.html


- (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;
        }
    }
}## 

Heading

##

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号