OS X开发,从通讯录调用kABAddressCountryCodeKey,获取不到。为什么呢?

我通过如下代码,从我的Mac上的通讯录,获取某人的国家。

let address = person.value(forProperty: kABAddressProperty) as? ABMultiValue

print(((adresse?.value(at: 0) as? NSMutableDictionary)?.value(forKey: kABAddressCountryKey) as? String) ?? "No Country")

print(((adresse?.value(at: 0) as? NSMutableDictionary)?.value(forKey: kABAddressCountryCodeKey) as? String) ?? "No Country")

kABAddressCountryKey对应的值,打印出来,是一个国家。
我也需要country code,kABAddressCountryCodeKey对应的值,但是结果打印出来的是 "No Country"。
哪里错了呢?

阅读 2.7k
1 个回答

代码没问题。
反复检查我的通讯录,2,020个有国家的联系人中,1,368没有国家编码。
再试验下,使用Mac的通讯录,取不到国家编码,使用手机通讯录倒是能取到。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题