Question

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?

Was it helpful?

Solution

Because you didn't post the full code I cannot debug the problem myself. But I think The answer is given by ikuragames in the comment.The most probable cause of the crash is, may be the record is null when executing the code.Debug the code and check the value of record and kABPersonFirstNameProperty.If I am right then you should have to assign some initial value for record or change your code according to the need. If it doesn't solve your problem then post the debugging information with a little bit in-depth description.

:)

Thank u..

OTHER TIPS

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]];
                }
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top