选择联系人后从地址簿中删除联系人
我正在研究我的应用程序和 iPhone 的地址簿之间的一些集成。这是我的程序的流程。
- 用户想要导入联系人
- 应用程序向用户呈现“ABPeoplePickerNavigationController”。
- 用户选择他们想要的联系人:
- 调用委托方法:
这是代码:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
self.selectedContact = person;
[self showNewContactViewThroughController:peoplePicker withRecord:person];
NSLog(@"should continue after selecting");
return NO;
}
5: 在 - (void)showNewContactViewThroughController:withRecord:
中,我们创建 AbNewPersonViewController。
`ABNewPersonViewController *newController = [[ABNewPersonViewController alloc] init];`
`newController.displayedPerson = person;`
`newController.newPersonViewDelegate = self;`
然后推一下。
6: 用户点击“取消”退出 ABNewPersonViewController 视图。
7:检查联系人应用程序,他们在步骤 3 中选择的联系人已经消失。噗,消失了,删除了,删除了。
为了解决此问题,我保存了 ABRecordRef(到实例变量“selectedContact”)。然后,在 - (void)newPersonViewController:didCompleteWithNewPerson:
我有:
if (person) {
//do stuff with the person
else {
///
/// This means they canceled, so we need to save the old person back
///
if (self.selectedContact) {
ABAddressBookRef addressBook = ABAddressBookCreate();
CFErrorRef error = NULL;
ABAddressBookAddRecord(addressBook, self.selectedContact, &error);
if (error != NULL) {
NSLog(@"Error Adding Record: %@", error);
}
ABAddressBookSave(addressBook, &error);
if (error != NULL) {
NSLog(@"AccountDetailTableViewController.newPersonViewController() The old contact was not saved successfully. %@", error);
}
self.selectedContact = nil;
}
}
但是,这似乎没有做任何事情。代码已执行,但“旧联系人”self.selectedContact 未保存到地址簿中。所以,我的联系方式仍然在消失。我做错了什么?看起来好像如果您在 ABNewPersonViewController 中单击“取消”,它会“删除”从地址簿中提供的数据?那么我给它的人就死了?任何帮助将不胜感激!
I'm working on some integration between my application and the iPhone's AddressBook. Here is the flow of my program.
- User wants to import a contact
- App Presents "ABPeoplePickerNavigationController" to the User.
- User selects the contact they want:
- Delegate Method is called:
Here is the code:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
self.selectedContact = person;
[self showNewContactViewThroughController:peoplePicker withRecord:person];
NSLog(@"should continue after selecting");
return NO;
}
5: In - (void)showNewContactViewThroughController:withRecord:
We create the AbNewPersonViewController.
`ABNewPersonViewController *newController = [[ABNewPersonViewController alloc] init];`
`newController.displayedPerson = person;`
`newController.newPersonViewDelegate = self;`
And then push it.
6: User hits "Cancel" to quit the ABNewPersonViewController view.
7: Check the Contacts app, the contact they selected in step 3 is gone. Poof, gone, deleted, removed.
In an attempt to fix this issue, I save the ABRecordRef (to the instance variable "selectedContact"). Then, in - (void)newPersonViewController:didCompleteWithNewPerson:
I have:
if (person) {
//do stuff with the person
else {
///
/// This means they canceled, so we need to save the old person back
///
if (self.selectedContact) {
ABAddressBookRef addressBook = ABAddressBookCreate();
CFErrorRef error = NULL;
ABAddressBookAddRecord(addressBook, self.selectedContact, &error);
if (error != NULL) {
NSLog(@"Error Adding Record: %@", error);
}
ABAddressBookSave(addressBook, &error);
if (error != NULL) {
NSLog(@"AccountDetailTableViewController.newPersonViewController() The old contact was not saved successfully. %@", error);
}
self.selectedContact = nil;
}
}
However, this doesn't seem to do anything. The code is executed, but the "Old Contact", self.selectedContact, is not saved to the AddressBook. So, my contacts are still disappearing. What am I doing wrong? It appears as though if you hit Cancel in the ABNewPersonViewController, it "removes" the data it was given from the Address Book? So the person I give it then dies? Any help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过不使用
ABNewPersonViewController
解决了这个问题,而是在用户选择他们想要使用的人后使用ABPersonViewController
。该信息不再被删除。I solved this problem by NOT using the
ABNewPersonViewController
, but rather by using theABPersonViewController
after the user selected the person they want to use. The information is no longer being deleted.