简体   繁体   中英

Not able to make a phone call, email someone etc using the iOS address book framework

I have implemented an address book framework in my app and I am creating a new contact and setting some information in it and then display it on later. But when I am actually displaying the view I cannot get the phone app or the email app to open up when I tap the respective buttons. Here is how I create and save the information:

ABRecordRef record = ABPersonCreate();   

ABMutableMultiValueRef phoneMulti = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABDictionaryPropertyType);
ABMutableMultiValueRef emailMultiValue = ABMultiValueCreateMutable(kABPersonEmailProperty);
ABMultiValueAddValueAndLabel(emailMultiValue, @"someone_somewhere@abc.com", (CFStringRef)@"email", NULL);

CFStringRef keys[5];
CFStringRef values[5];
keys[0] = kABPersonAddressStreetKey;
keys[1] = kABPersonAddressCityKey;
keys[2] = kABPersonAddressStateKey;
keys[3] = kABPersonAddressZIPKey;
keys[4] = kABPersonAddressCountryKey;

values[0] = CFSTR("ABC way"); 
values[1] = CFSTR("Toronto");       
values[2] = CFSTR("ON");                
values[3] = CFSTR("L1A2B3");            
values[4] = CFSTR("Canada");            //This is static
CFDictionaryRef aDict = CFDictionaryCreate(
                                           kCFAllocatorDefault,
                                           (void *)keys,
                                           (void *)values,
                                           5,
                                           &kCFCopyStringDictionaryKeyCallBacks,
                                           &kCFTypeDictionaryValueCallBacks
                                           );


ABMultiValueAddValueAndLabel(address, aDict, kABHomeLabel, NULL);
CFRelease(aDict);

// Set up Phone Number
ABMultiValueAddValueAndLabel(phoneMulti, @"12345678910", kABWorkLabel, NULL);


ABRecordSetValue(record, kABPersonFirstNameProperty, firstName, NULL);
ABRecordSetValue(record, kABPersonLastNameProperty, lastName, NULL);
ABRecordSetValue(record, kABPersonNoteProperty, (CFStringRef)@" ", NULL);
ABRecordSetValue(record, kABPersonAddressProperty, address, NULL);
ABRecordSetValue(record, kABPersonEmailProperty, emailMultiValue, NULL);
ABRecordSetValue(record, kABPersonPhoneProperty, phoneMulti, nil);

I am using an UnknownPersonViewController to access the record in another view.

ABUnknownPersonViewController *contactDetailsView = [[ABUnknownPersonViewController alloc]init];

contactDetailsView.allowsActions = YES;
contactDetailsView.displayedPerson = record;

[[self navigationController] pushViewController:contactDetailsView animated:YES];

Why can't I do anything (make a call, email, write a note) when I am in my contactDetailsView ? How can I fix it? I am using iOS 5.

Set

contactDetailsView.unknownPersonViewDelegate = self;

Then implement

- (BOOL)unknownPersonViewController:(ABUnknownPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
    return YES;
}

And of course the .h file should have:

MyClass : <ABUnknownPersonViewControllerDelegate>

Be sure to test behavior on device and not on simulator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM