birthdayContactIdentifier BAD_ACCESS

时间:2016-07-05 08:40:42

标签: ios swift contacts ekevent

当我从EKEvent访问属性birthdayContactIdentifier时,我总是立即收到BAD_ACCESS错误(甚至无法检查)

这是我用来获取的代码

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)") // BAD_ACCESS  
                }  
            }  
        }  
     }   
  }  
} 

1 个答案:

答案 0 :(得分:0)

我发现错误号为22475180 here。试试birthdayPersonID。从iOS 9开始,它目前已被弃用,但它的工作方式可能不同