Iphone - 检查地址簿中是否已存在组名 [英] Iphone - Check if a group name already exist in addressbook
本文介绍了Iphone - 检查地址簿中是否已存在组名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问候,
我正在制作一个地址簿应用程序,以便可以在群组下创建联系人。我已经能够创建组。但每次我启动应用程序时,该组都会重复。
I am making an address book application so that contacts can be created under groups. I have been able to create the groups . but everytime i start the application the group is repeated .
我如何检查该组是否已存在。
我曾经使用过ABAddressBookCopyArrayOfAllGroups,但是在打印数组的NSLog时我没有成功地从该数组中检索组的名称我得到了一个
How is that i can check if the group already exist. I had used the ABAddressBookCopyArrayOfAllGroups but havent been successful in retrievin the name of the group from that array while printting the NSLog of the array i get an
推荐答案
+ (BOOL)checkIfGroupExistInAddressBook:(NSString*)gName{
BOOL gExist = NO;
ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *groups = (NSArray *) ABAddressBookCopyArrayOfAllGroups(addressBook);
// Check group in existing Address book groups
for (id _group in groups)
{
//NSString *currentGroupName = [[[NSString alloc] init] autorelease];
NSString *currentGroupName = (NSString*) ABRecordCopyValue(_group, kABGroupNameProperty);
//(ABRecordRef)group]
// If group exist return YES
if ([currentGroupName isEqualToString:gName]){
gExist = YES;
CFRelease(currentGroupName);
break;
}
CFRelease(currentGroupName);
}
CFRelease(addressBook);
if (groups) {[groups release];groups = nil;}
// If group Dose not exist return NO;
return gExist;
}
这篇关于Iphone - 检查地址簿中是否已存在组名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文