gpt4 book ai didi

ios - ABRecordCopyValue 不同的值?

转载 作者:行者123 更新时间:2023-11-29 04:12:52 24 4
gpt4 key购买 nike

我正在尝试在我的联系人列表中进行搜索,但是如果从应用程序商店新鲜执行,或者从 TestFlight 执行(正如我现在测试的那样),此代码会崩溃。如果我卸载该应用程序并点击“运行”,它就会完美运行。但是直接从 TestFlight 执行它会崩溃,崩溃日志指出它在 i 的行中失败了

BOOL found = NO;
NSString *name;
int i = 0;
NSLog(@"Hay %i", [people count]);
while (!found && i < [people count]) {
ABRecordRef person = (ABRecordRef)[people objectAtIndex:i];
ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSLog(@"address: %@", multi);
//Freshly from TestFlight this prints "address: Denis" wich is a contac, executed from Xcode it prints, address: ABMultiValueRef 0x1fb68400 with 1 value(s), so I see here's the problem

if([[(NSMutableString*)ABMultiValueCopyValueAtIndex(multi, 0) componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] componentsJoinedByString:@""]){

NSMutableString *tempPhone = [[NSMutableString alloc]initWithString:[[(NSMutableString*)ABMultiValueCopyValueAtIndex(multi, 0) componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] componentsJoinedByString:@""]];

NSLog(@"telf: %@", tempPhone);

int length = [tempPhone length] - 9;
NSString *tempPhone2;
if(length >= 0){
tempPhone2 = [[NSString alloc]initWithString:[tempPhone substringFromIndex:length]];
}

NSLog(@"el telf: %@ y nombre %@ int %i",tempPhone2, [NSString stringWithFormat:@"%@ %@",ABRecordCopyValue(person, kABPersonFirstNameProperty) ? (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty) : @"",ABRecordCopyValue(person, kABPersonLastNameProperty) ? (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty) : @""], i);

if([[key objectForKey:@"phone"] isEqualToString:tempPhone2]){

name = [NSString stringWithFormat:@"%@ %@",ABRecordCopyValue(person, kABPersonFirstNameProperty) ? (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty) : @"",ABRecordCopyValue(person, kABPersonLastNameProperty) ? (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty) : @""];

found = YES;

}
}

i++;

}

在这一行 NSLog(@"address: %@", multi); 当 TestFlight 的 Fresh“address: Denis”是一个联系人时,它会打印,从 Xcode 执行它打印,“地址:ABMultiValueRef 0x1fb68400 with 1 value(s)...”,所以我看到了问题所在,即差异,我不明白的是为什么不同,你能告诉我为什么吗?

最佳答案

您似乎没有正确访问地址簿数据。我明白,正确的方法是这样的:

ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
NSString* label;
for (int i = 0; i < ABMultiValueGetCount(multi); i++) {
label = (NSString*)ABMultiValueCopyLabelAtIndex(multi, i);
... <DO YOUR PROCESSING on label>
}

希望这有帮助。

关于ios - ABRecordCopyValue 不同的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14162439/

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