• iPhone 添加删除联系人组


    iPhone添加删除联系人组

    1,添加AddressBook.framework

    2,添加联系人群组

    View Code
    - (void)addGroup
    {
        //Create group
        ABAddressBookRef ab = ABAddressBookCreate();
        CFErrorRef error;
        ABRecordRef group = ABGroupCreate();
        ABRecordSetValue(group, kABGroupNameProperty,@"new group", &error);
        ABAddressBookAddRecord(ab, group, &error);
        ABAddressBookSave(ab, &error);
        
        //Create new person and save to this group
        ABRecordRef record = ABPersonCreate();
        BOOL isSuccess ;
        
        isSuccess  = ABRecordSetValue(record, kABPersonNicknameProperty,@"GroupMember nick name", &error);
        isSuccess = ABRecordSetValue(record, kABPersonMiddleNameProperty, @"Middle name", &error);
        
        ABMutableMultiValueRef copyOfPhones = ABMultiValueCreateMutable(kABPersonPhoneProperty);
        
        CFTypeRef phone= CFSTR("123000222111");
        
        ABMultiValueAddValueAndLabel(copyOfPhones, phone,kABPersonPhoneMobileLabel,NULL);
        
        isSuccess = ABRecordSetValue(record, kABPersonPhoneProperty, copyOfPhones, &error);
        
        isSuccess = ABAddressBookAddRecord(ab, record, &error);
        isSuccess = ABAddressBookSave(ab, &error);
        
        ABGroupAddMember(group, record, &error);
        
        NSLog(@"is success %d", isSuccess);
        
        ABAddressBookSave(ab, &error);
        CFRelease(group);  
    }

    3,获取联系人群组

    View Code
    - (NSArray *)getGroups
    {
        NSMutableArray *groupNames = [[[NSMutableArray alloc] init] autorelease];
        ABAddressBookRef ab = ABAddressBookCreate();
        NSArray *array = (NSArray *)ABAddressBookCopyArrayOfAllGroups(ab);
        for (int i = 0 ; i < [array count]; i++)
        {
            ABRecordRef group = [array objectAtIndex:i];
            CFTypeRef groupName = ABRecordCopyValue(group, kABGroupNameProperty);
            NSString *groupNameStr = [NSString stringWithFormat:@"%@", (NSString *)groupName];
            NSLog(@"groupNames is %@", groupNameStr);
            [groupNames addObject:groupNameStr];
            CFRelease(groupName);
        }
        return groupNames;
    }

    4,删除联系人群组

    View Code
    //delete all groups
    -  (void) DeleteGroups{
    ABAddressBookRef ab = ABAddressBookCreate();
    CFErrorRef error;
    //get all groups
    CFArrayRef groups=ABAddressBookCopyArrayOfAllGroups(ab);
    //groups' count
    CFIndex groupCount=ABAddressBookGetGroupCount(ab);
    
    for (int i=0; i< groupCount;i++){
    ABRecordRef group=CFArrayGetValueAtIndex(groups, i);
    //delete
    ABAddressBookRemoveRecord(ab, group, &error);
    ABAddressBookSave(ab, &error);
    CFRelease(groups);  
    }

    5,关于联系人的操作可以参见我的文章:iPhone通讯录联系人的增加、删除、修改的操作

    6,本文写作的参考文章:iphone地址本操作ABAddressBook删除联系人与群组

  • 相关阅读:
    Aria2任意文件写入漏洞
    webpack添加node_path不是('webpack' 不是内部或外部命令,也不是可运行的程序或批处理文件?)
    闭包的7种形式
    首页 多级展示
    velocity模板入门
    AngularJs 时间控件
    mybatis按时间条件搜索
    数据结构之线性表(双向循环链表)
    数据结构之线性表(链表)
    数据结构之线性表(顺序表)
  • 原文地址:https://www.cnblogs.com/cpcpc/p/2635876.html
Copyright © 2020-2023  润新知