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

By : Neal
Source: Stackoverflow.com
Question!

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?

Thanks

By : Neal


Answers

You should be able to weak-link the EventKit framework, then check at runtime for the existence of the classes you need. See also: EventKit in Universal app (OS3.2), iPhone checking for existance of AVCaptureSession Class and How do you optionally use iPhone OS 3.0 features in a 2.0 compatible app?

By setting your deployment target in your project settings to 3.0, but compiling against a 4.x SDK, the weak linking aspect should be taken care of for you.

By : bosmacs


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.



This video can help you solving your question :)
By: admin