简体   繁体   English

在iOS上检索多个电话联系人标签

[英]Retrieve multiple phone contact labels on iOS

Ios allows to store multiple Home/ Mobile/ Work numbers for a contact. ios允许存储一个联系人的多个家庭/移动/工作号码。 Is there a way to differentiate the two labels of Home phone number? 有没有办法区分家庭电话号码的两个标签? We receive the label Home for all the home numbers. 我们收到所有房屋号码的“房屋”标签。 Is there a option there to differentiate Home1, Home2 etc. The following code just retrieves as Home/ work/ Mobile for all the respective phone numbers 是否有区分Home1,Home2等的选项。以下代码仅针对所有各自的电话号码检索为Home / work / Mobile。

for(CFIndex j = 0; j < ABMultiValueGetCount(phones1); j++)
{      
  mobileLabel = (__bridge NSString*)ABMultiValueCopyLabelAtIndex(phones1, j);
  if ([contactPhoneentry containsObject:mobileLabel]) 
  {
      continue;
  }

  if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel])
  {
     home_mobile = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phones1,j);
     identstring = @"Mobile";
  }
  else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhoneIPhoneLabel])
  {
      home_mobile = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phones1,j);
       identstring = @"iPhone";
  }
  else if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMainLabel])
  {
      home_mobile = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phones1,j);
      identstring = @"Main";
  }
  else if([mobileLabel isEqualToString:(NSString *)kABPersonPhonePagerLabel])
  {
      home_mobile = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phones1,j);
      identstring = @"Pager";
  }
  else if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneHomeFAXLabel])
  {
      home_mobile = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phones1,j);
      identstring = @"Home Fax";
  }
  else if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneWorkFAXLabel])
  {
      home_mobile = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phones1,j);
      identstring = @"Work Fax";
  }
  else if([mobileLabel isEqualToString:@"_$!<Home>!$_"])
  {
      home_mobile = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phones1,j);
      identstring = @"Home";
  }
  else if ([mobileLabel isEqualToString:@"_$!<Work>!$_"])
  {
       home_mobile = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phones1,j);
       identstring = @"Work";
  }
  else
  {
       home_mobile = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phones1,j);
       identstring = @"Other";
  }

Is this right way to retrieve phone numbers and labels? 这是检索电话号码和标签的正确方法吗?

I'm not sure I completely understand what you're trying to accomplish, but you should not be using the label to distinguish one phone from another because, as you know, the labels are not unique. 我不确定我是否完全理解您要完成的任务,但是您不应该使用标签将一部手机与另一部手机区分开,因为如您所知,标签不是唯一的。 Each value in a multiValueRef, in this case each phone number, has a unique identifier. multiValueRef中的每个值(在本例中为每个电话号码)都有一个唯一的标识符。 This identifier is unique to the other identifiers within the multi value, so you can use it to identifier phone numbers even if you have multiple numbers with the same label. 此标识符对于multi值中的其他标识符是唯一的,因此即使您有多个带有相同标签的号码,也可以使用它来标识电话号码。

In your code above, you can get a phone numbers identifier by calling 在上面的代码中,您可以通过致电获取电话号码标识符

int identifier = ABMultiValueCopyLabelAtIndex(phones1, j);

It also looks like the code you posted is going to a lot of trouble to convert the label from address book into a localized label (ie '_$! < Work >!$_' to 'work'). 看起来您发布的代码在将标签从地址簿转换为本地化标签时也将遇到很多麻烦(即'_ $!<Work>!$ _'到'work')。 The address book framework has a function to handle this for you - ABAddressBookCopyLocalizedLabel(). 通讯簿框架具有为您处理此问题的功能-ABAddressBookCopyLocalizedLabel()。 For example - 例如 -

NSString *localizedString = (__bridge NSString *)ABAddressBookCopyLocalizedLabel(kABPersonPhoneMobileLabel);

This will set localizedString to "mobile". 这会将localizedString设置为“ mobile”。

It is not possible to distinguish the labels. 无法区分标签。 IOS (and OSX) do not require uniqueness of labels in an ABMultiValue . IOS(和OSX)不需要ABMultiValue中标签的唯一性。 It is fine to have multiple Home Phone numbers, for example. 例如,可以有多个家庭电话号码。 This also applies to addresses, emails, social profiles, etc. 这也适用于地址,电子邮件,社交资料等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM