OStack程序员社区-中国程序员成长平台

标题: iphone - ABGroupAddMember 在 iOS4 设备上不起作用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:44
标题: iphone - ABGroupAddMember 在 iOS4 设备上不起作用

下面的代码在模拟器(iOS 4 和 5)中运行良好,但在 iOS 4 设备上没有添加任何联系人。不返回错误。你知道为什么吗?

ABAddressBookRef ab = ABAddressBookCreate();
abGroupRef = ABAddressBookGetGroupWithRecordID(ab, 1);
ABRecordRef pRef = ABAddressBookGetPersonWithRecordID(ab, 1);
ABGroupAddMember(abGroupRef, pRef, &anError);
ABAddressBookSave(ab, &anError);

谢谢, --约瑟夫



Best Answer-推荐答案


Objective C 编程习惯总是检查返回 BOOL 值的函数的结果(例如 ABGroupAddMemberABAddressBookSaveNSArrayNSDictionary writeToFile 方法)before 检查是否有错误作为参数之一返回.

试试这样的:

ABAddressBookRef ab = ABAddressBookCreate();
ABRecordRef abGroupRef = ABAddressBookGetGroupWithRecordID(ab, 1);
ABRecordRef pRef = ABAddressBookGetPersonWithRecordID(ab, 1);
CFErrorRef anError = NULL;
NSError * anErrorAsObjectiveCObject; // for use with toll free bridged object magic

if(ABGroupAddMember(abGroupRef, pRef, &anError))
{
    if(ABAddressBookSave(ab, &anError))
    {
        NSLog(@"successfully saved");
    } else {
        anErrorAsObjectiveCObject = (__bridge_transfer NSError *) anError;
        NSLog( @"error in ABAddressBookSave - %@ %@", [anErrorAsObjectiveCObject domain], [anErrorAsObjectiveCObject localizedDescription] );
    }
} else {
    anErrorAsObjectiveCObject = (__bridge_transfer NSError *) anError;
    NSLog( @"error in ABGroupAddMember - %@ %@", [anErrorAsObjectiveCObject domain], [anErrorAsObjectiveCObject localizedDescription] );
}

关于iphone - ABGroupAddMember 在 iOS4 设备上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8525360/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4