美文网首页
【AddressBook】ABMultiValue - 多信息

【AddressBook】ABMultiValue - 多信息

作者: 居然是村长 | 来源:发表于2016-06-15 23:33 被阅读718次

其实还是 CFTypeRef 类型,添加类似多个手机号的多信息;依旧使用ABRecord 类添加

  • 创建
    ABMutableMultiValueRef muRef = ABMultiValueCreateMutable(kABStringPropertyType);
//    ABMutableMultiValueRef muRefCopy = ABMultiValueCreateMutableCopy(phones);
  • 操作
    if (ABMultiValueAddValueAndLabel(muRef, @"13456990987", (__bridge CFStringRef)@"测试标题", NULL)) {
        NSLog(@"添加");
    }
    
    if (ABMultiValueInsertValueAndLabelAtIndex(muRef, @"13456990987", (__bridge CFStringRef)@"测试标题", 0, NULL)) {
        NSLog(@"指定位置添加");
    }
    
    if (ABMultiValueRemoveValueAndLabelAtIndex(muRef, 0)) {
       NSLog(@"指定位置移除");
    }
    
    if (ABMultiValueReplaceValueAtIndex(muRef, @"13456990987", 0)) {
        NSLog(@"指定位置,替换内容");
    }
    
    if (ABMultiValueReplaceLabelAtIndex(muRef, (__bridge CFStringRef)@"测试标题啊啊啊", 0)) {
        NSLog(@"指定位置,替换标题");
    }
    
    // 这个是 ABRecord 类的 基础添加信息
    if (ABRecordSetValue(person, kABPersonPhoneProperty, muRef, NULL)) {
        NSLog(@"修改信息");
    };
  • 获取
    // 复制
    ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
    
    // 属性类型
    ABPropertyType pType = ABMultiValueGetPropertyType(phones);
    
    // 数据条数(例如:联系号码条数)
    CFIndex count = ABMultiValueGetCount(phones);
    
    // 取所有值 ()
    CFArrayRef array = ABMultiValueCopyArrayOfAllValues(phones);
    
    // 取某条值(187-6711-xxxx)
    CFTypeRef value = ABMultiValueCopyValueAtIndex(phones, 0);
    
    // 值的 标题(浙江 杭州 移动)
    CFStringRef str = ABMultiValueCopyLabelAtIndex(phones, 0);
    
    // 某位置的id
    ABMultiValueIdentifier idindex = ABMultiValueGetIdentifierAtIndex(phones, 0);

    // 某id 的位置
    CFIndex idValue = ABMultiValueGetIndexForIdentifier(phones, idindex);
    
    // 查找 某个值的index -1 不存在
    CFIndex indexOfValue = ABMultiValueGetFirstIndexOfValue(phones, @"123");
    1

AddressBook 的其他API

#include <AddressBook/ABGroup.h>
#include <AddressBook/ABSource.h>
这两个 还是没搞清楚 搞什么玩意,好像也没怎么用到;;

1

相关文章

网友评论

      本文标题:【AddressBook】ABMultiValue - 多信息

      本文链接:https://www.haomeiwen.com/subject/thmpdttx.html