选择联系人后从地址簿中删除联系人

发布于 2024-11-24 09:06:49 字数 2097 浏览 3 评论 0原文

我正在研究我的应用程序和 iPhone 的地址簿之间的一些集成。这是我的程序的流程。

  1. 用户想要导入联系人
  2. 应用程序向用户呈现“ABPeoplePickerNavigationController”。
  3. 用户选择他们想要的联系人:
  4. 调用委托方法:

这是代码:

- (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.

  1. User wants to import a contact
  2. App Presents "ABPeoplePickerNavigationController" to the User.
  3. User selects the contact they want:
  4. 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 技术交流群。

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

发布评论

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

评论(1

江湖正好 2024-12-01 09:06:49

我通过不使用 ABNewPersonViewController 解决了这个问题,而是在用户选择他们想要使用的人后使用 ABPersonViewController 。该信息不再被删除。

I solved this problem by NOT using the ABNewPersonViewController, but rather by using the ABPersonViewController after the user selected the person they want to use. The information is no longer being deleted.

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