Reputation: 43
var eventStore: EKEventStore?
@IBAction func bbbbbbb(sender: UIButton) {
if eventStore == nil {
eventStore = EKEventStore()
}
self.eventStore?.requestAccessToEntityType(EKEntityType.Event, completion: { (aBool, error) -> Void in
print(error, aBool)
})
}
the print is nil, false always... Its behaving like the user has already denied access, but the promt is never being showed. The same code of course works in a new blank app on the same devices. Things I have tried: resting setting on device, simulator and using a new device where the app has never been installed and of course cleaning the project, but with no success. Plus in the app settings the calendar permission is not showing as well. Any ideas of what is going on?
Upvotes: 2
Views: 2681
Reputation: 81
With iOS 10, you need to add the following key in your plist
to allow an app to access the calendar (if not, the app will simply crash when requesting access):
key: "Privacy - Calendars Usage Description"
value: "$(PRODUCT_NAME) calendar events"
see here:
https://iosdevcenters.blogspot.com/2016/09/infoplist-privacy-settings-in-ios-10.html
Upvotes: 8
Reputation: 33
Try the following code
let eventStore = EKEventStore()
eventStore.requestAccessToEntityType(EKEntityType.Event) { (granted: Bool, error: NSError?) -> Void in
if granted{
print("Got access")
let defaultCalendar = eventStore.defaultCalendarForNewEvents
print("\(defaultCalendar.calendarIdentifier)")
}else{
print("The app is not permitted to access reminders, make sure to grant permission in the settings and try again")
}
}
Upvotes: 1