ABRecordCopyValue() SIGSEGV

670 views Asked by At

I'm currently fetching all the contacts from the adress-book and want to save the last date I met a particular contact. Therefore I'm fetching the calendar at the same time as follows:

for (EKEvent* event in events) {
            for (EKParticipant* attende in [event attendees]) {
                ABRecordRef record = [attende ABRecordWithAddressBook:addressBook];
                if([contact.name isEqualToString:[NSString stringWithFormat:@"%@ %@", (__bridge NSString *)ABRecordCopyValue(record, kABPersonFirstNameProperty), (__bridge NSString *)ABRecordCopyValue(record, kABPersonLastNameProperty)]]){
                        contact.lastMet = [NSString stringWithFormat:@"%@",[formatter stringFromDate:event.endDate]];
                    }

            }

        }

Sadly the code crashes at the "if"-statement line with signal SIGSEGV, the crash log indicates that the failure occurs with ABRecordCopyValue()...Any suggestions how to fix this issue?

1

There are 1 answers

0
ikuramedia On

You can simply test for the record being non-nil at the beginning of the if-statement. If the test fails, then the rest of the expression is not evaluated. So the following should cure your crash.

for (EKEvent* event in events) {
        for (EKParticipant* attende in [event attendees]) {
            ABRecordRef record = [attende ABRecordWithAddressBook:addressBook];
            if(record && [contact.name isEqualToString:[NSString stringWithFormat:@"%@ %@", (__bridge NSString *)ABRecordCopyValue(record, kABPersonFirstNameProperty), (__bridge NSString *)ABRecordCopyValue(record, kABPersonLastNameProperty)]]){
                    contact.lastMet = [NSString stringWithFormat:@"%@",[formatter stringFromDate:event.endDate]];
                }
        }
    }