开发者

ABGroupCreate problem [duplicate]

开发者 https://www.devze.com 2023-02-09 06:26 出处:网络
This question already has answers here: Obtaining Specific ABSource from ABAddressBook in iOS 4+ (4 answers)
This question already has answers here: Obtaining Specific ABSource from ABAddressBook in iOS 4+ (4 answers) Closed 3 years ago.

I have problem with a开发者_如何学编程dding a group to the iOS address book. In the simulator everything works great, I add the group, and assign contacts to it. But when the same application runs on an iPhone or iPad the group is not created and the new contacts are therefore not assigned to that specific group.

The method ABGroupCreate does not return any error.

Solution please? :)


Since you didn't paste your code, i can not know the problem. anyway- this is a method i use in my apps, it creates a group and return its ID so you can store it for later use, works great for me-

-(NSInteger) createNewGroup:(NSString*)groupName {

    ABAddressBookRef addressBook = ABAddressBookCreate();
    ABRecordRef newGroup = ABGroupCreate();
    ABRecordSetValue(newGroup, kABGroupNameProperty,groupName, nil);
    ABAddressBookAddRecord(addressBook, newGroup, nil);
    ABAddressBookSave(addressBook, nil);
    NSInteger groupId = ABRecordGetRecordID(newGroup);
    CFRelease(addressBook);
    CFRelease(newGroup);
    return groupId;
}

Good luck shani

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号