【问题标题】:Read Address Book data in iOS using Swift使用 Swift 在 iOS 中读取通讯录数据
【发布时间】:2015-03-23 17:55:43
【问题描述】:

我还是 Swift 的新手,并且在 iOS 中使用地址簿,事实证明它是一个熊。具体来说,我正在尝试读取联系人的“社交资料”。

对于像名字/姓氏这样的字符串值,这是可行的:

let firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty).takeRetainedValue() as String

但是当我尝试对kABPersonSocialProfileProperty 属性“(kABMultiDictionaryPropertyType 类型的多值属性)”做基本相同的事情时,如下所示:

let socialData = ABRecordCopyValue(person, kABPersonSocialProfileProperty)

我收到错误:'CFString' is not convertible to 'ABPropertyID'

我不清楚它为什么会抛出这个错误。

我已阅读 Apple iOS 开发人员文档,似乎 ABRecordCopyValue 正确的功能(“返回记录属性的值。”)......所以我不是确定从这里去哪里。

可能有人解释错误以及我应该去哪里阅读地址簿中联系人的社交资料数据?谢谢。

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    这是我最终做的(请原谅部分 sn-p,匹配函数的一部分):

    let socialProfiles: ABMultiValueRef = ABRecordCopyValue(person, kABPersonSocialProfileProperty).takeRetainedValue() as ABMultiValueRef
    for var index:CFIndex = 0; index < ABMultiValueGetCount(socialProfiles); ++index {
    
        if let socialProfile: AnyObject = ABMultiValueCopyValueAtIndex(socialProfiles, index).takeRetainedValue() as? NSDictionary {
    
            let service = socialProfile["service"] as String
            if service == "Twitter" {
    
                let username = socialProfile["username"] as String
                if username == paramUsername {
                    return (true, person)
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多