无法使用 iOS 地址簿框架拨打电话、向某人发送电子邮件等
我在我的应用程序中实现了一个地址簿框架,我正在创建一个新联系人并在其中设置一些信息,然后稍后显示它。但是,当我实际显示视图时,当我点击相应的按钮时,我无法打开电话应用程序或电子邮件应用程序。以下是我创建和保存信息的方法:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置
然后实施
当然,.h 文件应该具有:
确保在设备上而不是模拟器上测试行为
Set
Then implement
And of course the .h file should have:
Be sure to test behavior on device and not on simulator