2011-07-22 12 views
3

アドレス帳にコードでいくつかのグループを作成しました。特定のグループを削除するには、以下のコードを使用します。 ABAddressBookRemoveRecord()は、YESを返します。グループはまだそこにいる! コードに問題がありますか?アドレス帳からグループを削除する

BOOL res; 
CFErrorRef error; 
ABAddressBookRef ab = ABAddressBookCreate(); 

NSArray *groups = (NSArray *) ABAddressBookCopyArrayOfAllGroups(ab); 

for (id _group in groups) 
{ 
    NSString *currentGroupName = [[NSString alloc] init]; 
    currentGroupName = (NSString*) ABRecordCopyValue(_group, kABGroupNameProperty); 

    if ([groupName isEqualToString:currentGroupName]) 
    { 
     [currentGroupName release]; 
     res = ABAddressBookRemoveRecord(ab, _group, &error); 
     return res; 
    } 
    [currentGroupName release]; 
} 

return NO; 

答えて

5

これを返信する前にABAddressBookSave(ab, nil);を追加してください。

+0

ありがとう、私はそれを保存する必要があるか分からなかった。 :) – Hadu

+0

ありがとう情報 – iOSAppDev

関連する問題