如何在通讯录中保存联系人之前检查是否添加了组织名称? [英] how to check whether organization name is added before saving contact in address book?

查看:120
本文介绍了如何在通讯录中保存联系人之前检查是否添加了组织名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个AddressBook项目,我的要求之一是在使用我的应用程序手动添加新联系人时,它应该检查用户是否输入了组织字段值。

I am working on a AddressBook project, One of my requirement is While adding new Contacts manually using my application it should check whether "Organization field" value is entered by user/not.

我在导航栏上添加了(+)按钮,其中包含以下代码片段:

I have Add(+) button on my Navigation Bar with d following code snippet:

UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self 
action:@selector(add:)];
self.navigationItem.rightBarButtonItem = addButton;

点击此添加按钮时会显示当前模态视图,原生地址簿;

A present modal view appears on clicking this add button, by native Address Book;

-(void)add:(id)sender
{
    ABNewPersonViewController *view = [[ABNewPersonViewController alloc] init];
    view.newPersonViewDelegate = self;
    UINavigationController *newNavigationController = [[UINavigationController alloc] initWithRootViewController:view];
    [self presentModalViewController:newNavigationController animated:YES];
}

- (void)newPersonViewController:(ABNewPersonViewController *)newPersonView didCompleteWithNewPerson:(ABRecordRef)person
{
    newPersonView.displayedPerson = person;
    [self dismissModalViewControllerAnimated:YES];
    [table reloadData];
}

联系人保存到我的地址之前我想检查用户是否有是否添加了组织领域。如果是空白/无,我想显示一个警告框,要求填写组织价值。这是强制性的,一旦用户提供了组织价值,那么联系人将被保存到AddressBook。

Before contact is saved to my address Book i want to check if the user has added "Organization field" or not. In case of blank/nil i want to show a Alert Box asking for filling Organization value. It is mandatory, once user provides Organization value then contact would be saved to AddressBook.

编辑:如下面Fabio所建议,我更新了我的代码..

As suggested below by Fabio, i updated my codes..

- (void)newPersonViewController:(ABNewPersonViewController *)newPersonView didCompleteWithNewPerson:(ABRecordRef)person{

NSString *company = [NSString stringWithFormat: @"%@", ABRecordCopyValue(person, kABPersonOrganizationProperty)];
if ([company isEqualToString: @"(null)"]) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Value Required!" message:@"Please provide some value for ORGANIZATION Field..." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}
else
{
 newPersonView.displayedPerson = person;
 [self dismissModalViewControllerAnimated:YES];
}
}

有了这个,我可以向用户提供字段值。它还会更新后续创建的记录。但是,由于MODAL VIEW被解雇,详细视图(Native App的信息屏幕)显示没有关于联系人的信息。

With this i am able to show an Alert to the user to provide field value. It is also updating the subsequent record created. But, as the MODAL VIEW is Dismissed, the Detailed view(Info screen of Native App) shows no information about the contact.

此外,CANCEL按钮不起作用它的常规方式..我不能回到应用程序,因为它反复要求提供字段值,即使我提供并按下取消。

Also, CANCEL Button doesn't works in its regular way.. i can't go back to app, as it repeatedly ask to provide field value, even if i provide and press cancel.

可以任何一个指南我!

谢谢&问候

推荐答案

使用ABNewPersonViewController没有记录的方法,因为当调用委托方法时,此人已被保存由ABNewPersonViewController提供。
以前你应该制作自己的插入控制器并使用它。

There is no documented way to do this using ABNewPersonViewController, because when the delegate method is called, the person is already saved by the ABNewPersonViewController. Formerly you should made your own "insert controller" and use it.

但我尝试了这种解决方法并获得了这种行为(在iOS 6上):

But I tried this workaround and obtained this behavior (on iOS 6):

在委托方法中

- (void)newPersonViewController:(ABNewPersonViewController *)newPersonView didCompleteWithNewPerson:(ABRecordRef)person

您收到创建的新人的引用。
然后,您可以访问已保存的人员并检查公司是否已编译。如果没有,只是你不打电话

you receive a ref to the new person created. You can then access to the person saved and check if the company has been compiled. If not, simply you don't call

[self dismissModalViewControllerAnimated:YES];

ABNewPersonViewController将保持原位,您可以向用户显示警告,要求他编译公司。
字段将保持编译状态,ABNewPersonViewController链接到创建的新用户。

The ABNewPersonViewController will stay in position, and you can show an alert to the user asking him to compile the company. The fields will remain compiled and ABNewPersonViewController "linked" to the new user created.

然后,用户可以:


  • 编译公司字段 - >点击保存将更新已保存的人并为您的代表提供新数据,这样您就可以正确解除视图控制器

  • 点击取消 - >您收到取消,此人被ABNewPersonViewController本身删除

但......因为我找不到在任何地方记录的这种行为,我不确定

But...because I can't find this behavior documented in any place, I'm not sure if


  • 它是否适用于其他版本

  • 它将存活到审核流程(以前您没有使用私有API,但不确定当用户点击保存时不关闭viewcontroller对UI准则不利)

问候
Fabio

Regards Fabio

这篇关于如何在通讯录中保存联系人之前检查是否添加了组织名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆