无法使用 iOS 地址簿框架拨打电话、向某人发送电子邮件等

发布于 2024-12-20 11:04:25 字数 2671 浏览 3 评论 0原文

我在我的应用程序中实现了一个地址簿框架,我正在创建一个新联系人并在其中设置一些信息,然后稍后显示它。但是,当我实际显示视图时,当我点击相应的按钮时,我无法打开电话应用程序或电子邮件应用程序。以下是我创建和保存信息的方法:

ABRecordRef record = ABPersonCreate();   

ABMutableMultiValueRef phoneMulti = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABDictionaryPropertyType);
ABMutableMultiValueRef emailMultiValue = ABMultiValueCreateMutable(kABPersonEmailProperty);
ABMultiValueAddValueAndLabel(emailMultiValue, @"[email protected]", (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);

我使用 UnknownPersonViewController 来访问另一个视图中的记录。

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

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

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

当我在 contactDetailsView 中时,为什么我无法执行任何操作(打电话、发送电子邮件、写便条)?我该如何修复它?我正在使用 iOS 5。

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, @"[email protected]", (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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

指尖上的星空 2024-12-27 11:04:25

设置

contactDetailsView.unknownPersonViewDelegate = self;

然后实施

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

当然,.h 文件应该具有:

MyClass : <ABUnknownPersonViewControllerDelegate>

确保在设备上而不是模拟器上测试行为

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文