Search code examples
iosxamarin.ioseventkit

How to use EventKit (Calendar) integration and still support iOS 3.x (MonoTouch)?


I would like to use EventKit to integrate the Calendar in my iPhone and iPad apps. However, when I include this code such as using MonoTouch.EventKit the app will not run on my OS 3.x device (iPod touch 2G).

Is there a way to build an app in MonoTouch and still have the min OS version as 3.0 yet support iOS 4 and the EventKit at the same time? How can I include EventKit functionality for iOS 4 devices without breaking support for 3.0 devices?


Solution

  • As mentioned by bosmacs, to accomplish this you need to let MonoTouch know that you need to link against the EventKit framework "weakly". Weak bindings ensure that the framework is only loaded on demand the first time a class from the framework is required.

    To do this you should take the following steps:

    • Open your Project Options and navigate to the iPhone Build pane.
    • Add '-gcc_flags "-weak_framework
      iAd"' to the Extra Arguments for each configuration you wish to weakly link on

    In addition to this you will need to guard your usage of the types from running on older versions of iOS where they may not exist. There are several methods to accomplish this, but one of which is parsing UIDevice.CurrentDevice.SystemVersion.