EKEvent birthdayContactIdentifier

Hello everyone!

Updating my app to use new CNContact framework but have a huge problem with getting birthdayContactIdentifier from EKEvent object.

Getting EXE_BAD_ACCESS error message every time.

Filled a bug report a while ago but have no answer for it yet.

Dows anyone know any trick that will help me to solve this problem?

Thank you.

What is the bug number?

Bug number: 22475180

Thanks. I'm suspicious about something in the code you included in the bug. You're creating a local EKEventStore (localStore), but then in the completion block for requestAccessToEntityType:completion: you're generating a predicate from self.localStore (which does not appear to have been assigned anywhere). It's not clear that is the cause of the crash, but it looks suspicious to me. It would also be interesting to reproduce this crash with zombies enabled to find out what object it is crashing on.


If you happen to have a sample project that could get attached to the bug that would also be a big help.

Agree, code was not clear and look suspicious, but it was just misstype.

I created sample project, where i can send it?

Also, i reproduced crash with Zombie enabled and look like problem somewhere inside framework.


#

Event Type

∆ RefCt

RefCt

Timestamp

Responsible Library

Responsible Caller

0

Malloc

+1

1

00:04.434.155

Foundation

_getStringAtMarker

1

Autorelease

00:04.434.158

Foundation

_NSXPCSerializationStringForObject

2

CFRetain

+1

2

00:04.434.168

Foundation

_walkAndDecodeData

3

Release

-1

1

00:04.434.208

Foundation

__95-[NSXPCConnection _sendInvocation:withProxy:remoteInterface:withErrorHandler:timeout:userInfo:]_block_invoke320

4

CFRelease

-1

0

00:04.434.213

Foundation

__95-[NSXPCConnection _sendInvocation:withProxy:remoteInterface:withErrorHandler:timeout:userInfo:]_block_invoke320

5

Zombie

-1

00:04.434.375

EKEventTest

__28-[ViewController getEvents:]_block_invoke

If you have a sample project you'd want to attach it to the bug report that you filed.

Uploaded

Hello everyone!


Yesterday I started to port my old Address Book code to the new Contacts Framework and ran into the same BAD_ACCESS problem with birthdayContactIdentifer. Since my app is a calendar app I need to work with EKEvent objects and their birthdayContactIdentifer. There's no way around it.


I conducted some tests an wrote a simple app that just initializes the EKEventStore (and requests access) in order to then fetch all events of the following seven days. If any of the events are part of the birthday calendar it NSLogs the title and the birthdayContactIdentifier.


I implemeted the app both in Objective C and Swift 2 (using Xcode 7.0.1). Both apps NSLog the identifier (of the single birthday event inside my simulator) approximately 10% of the time. All other tries result in BAD_ACCESS. Dispatching the code inside the completion block to the main thread does not change the result.


The Zombie test yields the same result as posted by Sergey (at least for the Objective C version that is).


This is what an NSLog of the identifier looks like:


BirthdayTest[26543:91411653] Hans Tester’s Birthday
BirthdayTest[26543:91411653] ID: 20D681BC-6DBA-4D2B-AB64-5D375BD66CD1:ABPerson


At the moment I don't know what to do.


Frank


P.S.:


This is the code I used:


#import "ViewController.h"
@import EventKit;

@interface ViewController ()
@property (strong) EKEventStore *eventStore;
@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];

    self.eventStore = [[EKEventStore alloc] init];
    [self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error){
        if (granted) {
            NSDate *startDate = [NSDate date];
            NSDate *endDate = [startDate dateByAddingTimeInterval:7*86400];
       
            NSArray *events = [self.eventStore eventsMatchingPredicate:[self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:nil]];
       
            for (EKEvent *event in events) {
                if (event.calendar.type == EKCalendarTypeBirthday) {
                    NSLog(@"%@",event.title);
                    NSLog(@"ID: %@",event.birthdayContactIdentifier); // 90% of the time --> BAD_ACCESS
                }
            }
        }
    }];
}
@end


import UIKit
import EventKit
class ViewController: UIViewController {
  
    let eventStore : EKEventStore = EKEventStore()
    override func viewDidLoad() {
        super.viewDidLoad()
      
        eventStore.requestAccessToEntityType(.Event) { (granted, error) in
            if granted == true {
                let startDate = NSDate()
                let endDate = startDate.dateByAddingTimeInterval(7.0*86400.0)
              
                let events = self.eventStore.eventsMatchingPredicate(self.eventStore.predicateForEventsWithStartDate(startDate, endDate: endDate, calendars: nil))
              
                for event in events {
                    if event.calendar.type == .Birthday {
                        NSLog("\(event.title)")
                        NSLog("\(event.birthdayContactIdentifier)") // 90% of the time --> BAD_ACCESS
                    }
                }
            }
        }
      
    }
}

I found a workaround. It is not optimal, but gets the job done in most cases. I hope we can use the birthdayContactIdentifier in a future release of the SDK.

Hello Frank!

TBH, i lost the hope to get any answers from Apple about this bug and now workng on alternative way to get birthdays in my calendar app.

I getting the list of birthdays as NSDataComponents from contacts and building my own birthdays calendar inside app.


Sergey.

EKEvent birthdayContactIdentifier
 
 
Q