gpt4 book ai didi

ios - ABGroupCreate 不适用于 Exchange

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:51:25 24 4
gpt4 key购买 nike

当我在模拟器上运行这段代码时遇到了问题,我得到了组的 ID,但是当我在设备上运行它时,ID 设置为 -1 ... 但错误消息保持为空。

    -(NSNumber *)addGroupeToAddressbookWithName:(NSString *)name{
ABAddressBookRef addressBook = ABAddressBookCreate();
CFErrorRef error = NULL;
ABRecordRef group = ABGroupCreate();
ABRecordSetValue(group, kABGroupNameProperty,(__bridge CFStringRef)name, &error);
ABAddressBookAddRecord(addressBook, group, &error);
ABAddressBookSave(addressBook,&error);
NSNumber *gId = [NSNumber numberWithInt:ABRecordGetRecordID(group)];

CFRelease(group);
return gId;
}

我不知道有什么区别,也不知道如何让它在真实设备上运行。

编辑:发现如果我删除手机上的 exchange sync 就可以工作,但仍然希望它在能够在手机上拥有 exchange 帐户的同时工作。所以并没有真正解决问题

编辑/回答

发现是因为exchange不知道组,要保存一个组需要使用正确的源,另见:Obtaining Specific ABSource from ABAddressBook in iOS 4+

新代码:

-(NSNumber *)addGroupeToAddressbookWithName:(NSString *)name{
ABAddressBookRef addressBook = ABAddressBookCreate();
CFErrorRef error = NULL;
CFArrayRef sources = ABAddressBookCopyArrayOfAllSources(addressBook);
CFIndex sourceCount = CFArrayGetCount(sources);
NSNumber *gId = nil;
for (CFIndex i = 0 ; i < sourceCount; i++) {
ABRecordRef currentSource = CFArrayGetValueAtIndex(sources, i);
CFTypeRef sourceType = ABRecordCopyValue(currentSource, kABSourceTypeProperty);

BOOL isMatch = kABSourceTypeLocal == [(__bridge NSNumber *)sourceType intValue];
CFRelease(sourceType);

if (isMatch) {
ABRecordRef group = ABGroupCreateInSource(currentSource);//ABGroupCreate();
ABRecordSetValue(group, kABGroupNameProperty,(__bridge CFStringRef)name, &error);
ABAddressBookAddRecord(addressBook, group, &error);
ABAddressBookSave(addressBook,&error);
gId = [NSNumber numberWithInt:ABRecordGetRecordID(group)];
CFRelease(group);
CFRelease(currentSource);
break;
}
}

CFRelease(sources);
return gId;
}

最佳答案

发现是因为 exchange 不了解码,要保存组需要使用正确的源,另见:Obtaining Specific ABSource from ABAddressBook in iOS 4+

新代码:

-(NSNumber *)addGroupeToAddressbookWithName:(NSString *)name{
ABAddressBookRef addressBook = ABAddressBookCreate();
CFErrorRef error = NULL;
CFArrayRef sources = ABAddressBookCopyArrayOfAllSources(addressBook);
CFIndex sourceCount = CFArrayGetCount(sources);
NSNumber *gId = nil;
for (CFIndex i = 0 ; i < sourceCount; i++) {
ABRecordRef currentSource = CFArrayGetValueAtIndex(sources, i);
CFTypeRef sourceType = ABRecordCopyValue(currentSource, kABSourceTypeProperty);

BOOL isMatch = kABSourceTypeLocal == [(__bridge NSNumber *)sourceType intValue];
CFRelease(sourceType);

if (isMatch) {
ABRecordRef group = ABGroupCreateInSource(currentSource);//ABGroupCreate();
ABRecordSetValue(group, kABGroupNameProperty,(__bridge CFStringRef)name, &error);
ABAddressBookAddRecord(addressBook, group, &error);
ABAddressBookSave(addressBook,&error);
gId = [NSNumber numberWithInt:ABRecordGetRecordID(group)];
CFRelease(group);
CFRelease(currentSource);
break;
}
}

CFRelease(sources);
return gId;
}

关于ios - ABGroupCreate 不适用于 Exchange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9207958/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com