omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    2
    3
    2342
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • TheRealBret
      TheRealBret last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by omz

        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.

        1 Reply Last reply Reply Quote 0
        • TheRealBret
          TheRealBret last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors