Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Xcode calendar access error
-
I am trying to add an appointment to the native iOS calendar. I have the following code which I took from this forum last year.
from objc_util import * from ctypes import POINTER import threading import calendar, time store = ObjCClass('EKEventStore').alloc().init() access_granted = threading.Event() def completion(_self, granted, _error): access_granted.set() completion_block = ObjCBlock(completion, argtypes=[c_void_p, c_bool, c_void_p]) store.requestAccessToEntityType_completion_(0, completion_block) access_granted.wait() event = ObjCClass('EKEvent').eventWithEventStore_(store) event.title = 'test' event.startDate = ObjCClass('NSDate').dateWithTimeIntervalSince1970_(time.mktime(time.strptime('2017-06-18 12:00:00', '%Y-%m-%d %H:%M:%S'))) event.endDate = ObjCClass('NSDate').dateWithTimeIntervalSince1970_(time.mktime(time.strptime('2017-06-18 13:00:00', '%Y-%m-%d %H:%M:%S'))) event.setCalendar_(store.defaultCalendarForNewEvents()) LP_c_void_p = POINTER(c_void_p) err = LP_c_void_p() store.saveEvent_span_error_(event, 0, err)
The code works just fine in Pythonista. A new calendar event is created, after optionally asking for permission to the calendar. I've run this code in both Pythonista 2.7 and 3.
When I copy/paste this exact code into my Xcode project, it crashes when trying to set a value to the event.title parameter - I inserted console alerts between each line and it doesn't appear after this line. I'm not an expert in the objective C interface, so I'm perplexed why it works in the app but not in Xcode.
Any help is appreciated.
Thanks!
-
You need to change the
Info.plist
file to indicate how your app is using calendar data (the text that's shown in the permission dialog). From Apple's documentation:An iOS app linked on or after iOS 10.0 must include in its Info.plist file the usage description keys for the types of data it needs to access or it will crash. To access Reminders and Calendar data specifically, it must include NSRemindersUsageDescription and NSCalendarsUsageDescription, respectively.
-
I already have the calendar and reminder descriptions set to "${PRODUCT_NAME} needs X access"), and I am able to add a reminder, using the built-in Pythonista reminders library. It also passes the initial code which forces a check. I've confirmed in the settings and I do have the access to calendar in the 'on' state.