默认 iPhone 地址簿人员电话号码标签周围有哪些标签?
我的问题涉及 iPhone 上联系人列表的人员条目中一些默认电话号码标签周围的标记。
我已为“John Smith”创建了一个 iPhone 联系人列表地址簿条目,其中包含以下电话号码条目:
- 手机 (604) 123-4567
- iPhone (778) 123-4567
- 家庭 (604) 789-4561
- 工作 (604) 456-7891
- 总机 (604) 789-1234
- 扩音器 (234) 567-8990
请注意,前五个标签是联系人应用程序提供的默认标签,最后一个标签“扩音器”是自定义标签。
我编写了以下方法来检索和显示地址簿中每个人的标签和电话号码:
-(void)displayPhoneNumbersForAddressBook {
ABAddressBookRef book = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(book);
ABRecordRef record = CFArrayGetValueAtIndex(people, 0);
ABMultiValueRef multi = ABRecordCopyValue(record, kABPersonPhoneProperty);
NSLog(@"---------" );
NSLog(@"displayPhoneNumbersForAddressBook" );
CFStringRef label, phone;
for (CFIndex i = 0; i < ABMultiValueGetCount(multi); ++i) {
label = ABMultiValueCopyLabelAtIndex(multi, i);
phone = ABMultiValueCopyValueAtIndex(multi, i);
NSLog(@"label: \"%@\" number: \"%@\"", (NSString*)label, (NSString*)phone);
CFRelease(label);
CFRelease(phone);
}
NSLog(@"---------" );
CFRelease(multi);
CFRelease(people);
CFRelease(book);
}
这是我输入的地址簿条目的输出:
2010-03-08 13:24:28.789 test2m[2479:207] ---------
2010-03-08 13:24:28.789 test2m[2479:207] displayPhoneNumbersForAddressBook
2010-03-08 13:24:28.790 test2m[2479:207] label: "_$!<Mobile>!$_" number: "(604) 123-4567"
2010-03-08 13:24:28.790 test2m[2479:207] label: "iPhone" number: "(778) 123-4567"
2010-03-08 13:24:28.791 test2m[2479:207] label: "_$!<Home>!$_" number: "(604) 789-4561"
2010-03-08 13:24:28.791 test2m[2479:207] label: "_$!<Work>!$_" number: "(604) 456-7891"
2010-03-08 13:24:28.792 test2m[2479:207] label: "_$!<Main>!$_" number: "(604) 789-1234"
2010-03-08 13:24:28.792 test2m[2479:207] label: "megaphone" number: "(234) 567-8990"
2010-03-08 13:24:28.793 test2m[2479:207] ---------
标记字符是什么
_$!< and >!$_
除了 iPhone 之外,最周围的 默认标签为?
你能告诉我在“iPhone操作系统地址簿编程指南”中哪里可以找到这些信息吗?
感谢您的帮助。
My question concerns markup that surrounds some of the default phone number labels in the Person entries of the Contact list on the iPhone.
I have created an iPhone contact list address book entry for a person, "John Smith" with the following phone number entries:
- Mobile (604) 123-4567
- iPhone (778) 123-4567
- Home (604) 789-4561
- Work (604) 456-7891
- Main (604) 789-1234
- megaphone (234) 567-8990
Note that the first five labels are default labels provided by the Contacts application and the last label, "megaphone", is a custom label.
I wrote the following method to retrieve and display the labels and phone numbers for each person in the address book:
-(void)displayPhoneNumbersForAddressBook {
ABAddressBookRef book = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(book);
ABRecordRef record = CFArrayGetValueAtIndex(people, 0);
ABMultiValueRef multi = ABRecordCopyValue(record, kABPersonPhoneProperty);
NSLog(@"---------" );
NSLog(@"displayPhoneNumbersForAddressBook" );
CFStringRef label, phone;
for (CFIndex i = 0; i < ABMultiValueGetCount(multi); ++i) {
label = ABMultiValueCopyLabelAtIndex(multi, i);
phone = ABMultiValueCopyValueAtIndex(multi, i);
NSLog(@"label: \"%@\" number: \"%@\"", (NSString*)label, (NSString*)phone);
CFRelease(label);
CFRelease(phone);
}
NSLog(@"---------" );
CFRelease(multi);
CFRelease(people);
CFRelease(book);
}
and here is the output for the address book entry that I entered:
2010-03-08 13:24:28.789 test2m[2479:207] ---------
2010-03-08 13:24:28.789 test2m[2479:207] displayPhoneNumbersForAddressBook
2010-03-08 13:24:28.790 test2m[2479:207] label: "_$!<Mobile>!$_" number: "(604) 123-4567"
2010-03-08 13:24:28.790 test2m[2479:207] label: "iPhone" number: "(778) 123-4567"
2010-03-08 13:24:28.791 test2m[2479:207] label: "_$!<Home>!$_" number: "(604) 789-4561"
2010-03-08 13:24:28.791 test2m[2479:207] label: "_$!<Work>!$_" number: "(604) 456-7891"
2010-03-08 13:24:28.792 test2m[2479:207] label: "_$!<Main>!$_" number: "(604) 789-1234"
2010-03-08 13:24:28.792 test2m[2479:207] label: "megaphone" number: "(234) 567-8990"
2010-03-08 13:24:28.793 test2m[2479:207] ---------
What are the markup characters
_$!< and >!$_
surrounding most, save for iPhone, of the default labels for?
Can you point me to where in the "Address Book Programming Guide for iPhone OS" I can find the information?
Thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题。到目前为止,这是我的想法。
您看到的标记向系统表明这是默认标签而不是自定义标签。如果您运行此代码:
NSLog(kABOtherLabel);
你会得到这个结果:
_$!!$_
这就是存储在
kABOtherLabel
常量(CFStringRef 类型)中的值。我认为 iPhone 周围没有标记的原因是它是一个“自定义”标签,但它是由 Apple 而不是用户发起的。您可以为标签指定任何您喜欢的值,如上面的
megaphone
标签所示。但请注意,如果您尝试创建带有“其他”标签的电话号码(或电子邮件地址),而不使用kABOtherLabel
常量或其值_$!! $_
,系统会认为您正在创建自定义标签。就像这个例子一样:如果您在 iPhone 上编辑地址簿条目,它将显示在单独的自定义标签列表中。 (因此,“其他”有 2 种选择,一种是默认值,一种是自定义标签)
虽然这没有回答您的问题,但我希望它有所帮助。
I'm running into the same issue. This is what I think so far.
The markup that your seeing indicates to the system that this is a Default label and not a custom label. If you run this code:
NSLog(kABOtherLabel);
you'll ge this result:
_$!<Other>!$_
So that is the value stored in the
kABOtherLabel
constant (of type CFStringRef). I think the reasoniPhone
doesn't have the markup around it is becuase it's a 'Custom' label, but it's one originated by Apple instead of the user.You can give the label any value you like, as evidenced by your
megaphone
label above. But notice that if you try and create a phone number (or e-mail address) with the label 'other' without using thekABOtherLabel
constant or it's value_$!<Other>!$_
, the system will think that you're creating a custom label. Like in this example:And if you go and edit that Address Book entry on the iPhone, it will show up in a separate list of custom labels. (So there will be 2 choices for 'other', one in the defaults and one in the custom labels)
While this hasn't answered your question, I hope it helps.
这在新的 CNContact 框架 中基本相同,该框架取代了 ABAddressBook 作为推荐的方式处理联系人。
Apple 提供了六个默认标签,通过 手机特定的 CNLabeledValue 常量:
在其中五个常量中包含
_$!<
和>!$_
很可能是一个标记,表明字符串可以由操作本地化系统,考虑到方法 localizedString(forLabel:) 的可用性。我相信 iPhone 周围没有出现这些分隔符的原因是 Apple 没有对 iPhone 进行本地化,它在所有语言中都显示为“iPhone”。明智的行为是在显示字符串时隐藏这些分隔符,这使用
localizedString(forLabel:)
进行,如果编辑条目,则继续将这些分隔符与字符串一起存储,并将任何用户创建的标签映射到这些字符串,其中自定义标签等于这些字符串的主体,即 Mobile、Main、Pager 等。This is largely the same in the new CNContact framework that replaced ABAddressBook as the recommended way to handle contacts.
There are six default labels that Apple provides, which are referenced with phone-specific CNLabelledValue constants:
The inclusion of
_$!<
and>!$_
around five of these constants is most likely a marker that the strings can be localised by the operating system, given the availability of the method localizedString(forLabel:). I believe the reason these delimiters do not appear around iPhone is because Apple does not localize iPhone, which is displayed as "iPhone" in all languages.The sensible behaviour would be to hide these when displaying the string, which occurs using
localizedString(forLabel:)
, continue to store these delimiters with the string if editing the entry, and map any user-created label to these strings where the custom label was equal to the main body of these, i.e., Mobile, Main, Pager, and so on.我正在使用 iOS 14,不幸的是,在处理 Apple 的联系人 API 时这仍然是一个问题。我的解决方案不是最好的,但它有效。
斯威夫特5
I'm working with iOS 14 and unfortunately this is still a problem when dealing with Apple's Contact API. My solution is not the best, but it works.
Swift 5