iPhone 地址簿 - 如何使用我的应用程序中的应用程序创建新记录

发布于 2024-10-08 05:09:52 字数 167 浏览 6 评论 0原文

我正在尝试通过我的应用程序创建新的人员记录。我有姓名、电子邮件和电话号码。 我如何将它们传递到 newPerson 的模式视图? 我正在关注苹果的文档,但我被困住了。 我正在使用 ABNewPersonViewController。这是正确的吗?如何填写模式视图中的字段?

谢谢,

RL

I'm trying to create a new record of Person thru my App. I have the name, email and phone nr.
How can i pass them to the modal view of newPerson?
I'm following Apple's docs, but i'm stuck.
I'm using a ABNewPersonViewController. Is that correct? How do I fill the fields in the modal view?

Thanks,

RL

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

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

发布评论

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

评论(2

终难愈 2024-10-15 05:09:52

如果您已经有了详细信息并且只想将它们写入地址簿,那么您不需要 - ABNewPersonViewController。
ABNewPersonViewController用于让用户用iphone地址簿的通用控制器向地址簿添加记录。

相反,您应该执行以下操作:

a) 将地址簿 () 框架添加到您的应用程序中。

b) 将地址簿标题导入到您的视图中。

c) 创建地址簿实例和新记录:

ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate();
     ABRecordRef newPerson = ABPersonCreate();

d) 对于您使用的单值属性:

  ABRecordSetValue(newPerson, kABPersonFirstNameProperty, CFSTR("Katie"), nil);
  ABRecordSetValue(newPerson, kABPersonLastNameProperty, CFSTR("Bell"), nil);

e) 对于您使用的多值属性,例如电话号码/邮件:

ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);

    ABMultiValueAddValueAndLabel(multiPhone, @"054-5429920", kABHomeLabel, NULL);

    ABMultiValueAddValueAndLabel(multiPhone,@"02-9809878", kABWorkLabel, NULL); 

    ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);
    CFRelease(multiPhone);


        ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);

    ABMultiValueAddValueAndLabel(multiEmail, @"[email protected]", kABHomeLabel, NULL);

    ABRecordSetValue(newPerson, kABPersonEmailProperty, multiEmail, &error);
    CFRelease(multiEmail);

f) 保存对地址簿的更改,无需任何代码你写的如果没有这个就不会生效:

ABAddressBookAddRecord(addressBook, newPerson, nil);
    BOOL didAdd = ABAddressBookSave(addressBook, nil);

g) 释放记录和地址簿并检查记录是否添加:

CFRelease(newPerson);
    CFRelease(addressBook);
    NSLog(@"didAdd = %d",didAdd);

仅此而已
祝你好运
希望它对

沙尼有帮助

if you already have the details and you just want to write them to the address book then you don't need the - ABNewPersonViewController.
the ABNewPersonViewController is used for letting the user to add record to the address book with the common controller of the iphone address book.

instead you should do the following:

a) add the address book () frame work to your app.

b) import the address book headers to your view.

c) create an addressbook instanse and a new record:

ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate();
     ABRecordRef newPerson = ABPersonCreate();

d) for single value properties you use:

  ABRecordSetValue(newPerson, kABPersonFirstNameProperty, CFSTR("Katie"), nil);
  ABRecordSetValue(newPerson, kABPersonLastNameProperty, CFSTR("Bell"), nil);

e)for the multy value properties such as phone number / mail you use:

ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);

    ABMultiValueAddValueAndLabel(multiPhone, @"054-5429920", kABHomeLabel, NULL);

    ABMultiValueAddValueAndLabel(multiPhone,@"02-9809878", kABWorkLabel, NULL); 

    ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);
    CFRelease(multiPhone);


        ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);

    ABMultiValueAddValueAndLabel(multiEmail, @"[email protected]", kABHomeLabel, NULL);

    ABRecordSetValue(newPerson, kABPersonEmailProperty, multiEmail, &error);
    CFRelease(multiEmail);

f) save the changes to the address book, none of the code you wrote wond take effect with out this:

ABAddressBookAddRecord(addressBook, newPerson, nil);
    BOOL didAdd = ABAddressBookSave(addressBook, nil);

g) relese the record and the address book and check if the record addaed:

CFRelease(newPerson);
    CFRelease(addressBook);
    NSLog(@"didAdd = %d",didAdd);

thats all
good luck
hope it helped

shani

追风人 2024-10-15 05:09:52

如果要在 ABNewPersonViewController 中显示某些内容,则必须为要预填充的属性创建并设置 ABRecordRef,然后在 ABNewPersonViewController 上设置 displayedPerson 属性。所以一个简单的例子可能是:

- (void)createNewPerson
{
  // Create the pre-filled properties
  ABRecordRef newPerson = ABPersonCreate();
  CFErrorRef error = NULL;
  ABRecordSetValue(newPerson, kABPersonFirstNameProperty, CFSTR("John"), &error);
  ABRecordSetValue(newPerson, kABPersonLastNameProperty, CFSTR("Smith"), &error);
  NSAssert( !error, @"Something bad happened here." );

  // Create and set-up the new person view controller
  ABNewPersonViewController* newPersonViewController = [[ABNewPersonViewController alloc] initWithNibName:nil bundle:nil];
  [newPersonViewController setDisplayedPerson:newPerson];
  [newPersonViewController setNewPersonViewDelegate:self];

  // Wrap in a nav controller and display
  UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:newPersonViewController];
  [self presentModalViewController:navController animated:YES];

  // Clean up everything
  [navController release];
  [newPersonViewController release];
  CFRelease(newPerson);
}

If you want to display something in the ABNewPersonViewController, you have to create and set up an ABRecordRef for the properties you want to pre-fill and then set the displayedPerson property on ABNewPersonViewController. So a simple example may be:

- (void)createNewPerson
{
  // Create the pre-filled properties
  ABRecordRef newPerson = ABPersonCreate();
  CFErrorRef error = NULL;
  ABRecordSetValue(newPerson, kABPersonFirstNameProperty, CFSTR("John"), &error);
  ABRecordSetValue(newPerson, kABPersonLastNameProperty, CFSTR("Smith"), &error);
  NSAssert( !error, @"Something bad happened here." );

  // Create and set-up the new person view controller
  ABNewPersonViewController* newPersonViewController = [[ABNewPersonViewController alloc] initWithNibName:nil bundle:nil];
  [newPersonViewController setDisplayedPerson:newPerson];
  [newPersonViewController setNewPersonViewDelegate:self];

  // Wrap in a nav controller and display
  UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:newPersonViewController];
  [self presentModalViewController:navController animated:YES];

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