Handling Access to Calendars in iOS 6

I had to laugh at my last post. I went on hiatus in August 2010 and now I’m back, in 2012. I’ve been busy working on Skedi Family Calendar, which aggregates calendar data from different vendors such as Google Calendar, Microsoft Exchange, etc.

Anyway, the latest release of iOS (6.0) isolates a user’s calendars and blocks access by default. This presented a problem for us at Rodax Software because we also support earlier versions of iOS (i.e., 4 and 5) and we wanted to avoid using conditional compilation.

In iOS 6, access to the calendars is controlled through the EKEventStore class. In the past, we’d call a alloc/init and that was it.  This is unchanged; however, now we need to request permission and if granted, we can access the users calendars and events. Note: This request can only be performed once, which I’ll cover later.

 _store = [[EKEventStore alloc] init];

So, if we need to support earlier versions of iOS, how can we avoid using ugly preprocessor macros? Simple, use the power of Objective-C’s dynamic typing. In iOS 6, the method to request access in EKEventStore is requestAccessToEntityType. Hence, we need to determine if it’s available.

if([_store respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
	//invoke requestAccessToEntityType...

If the statement is true, request access:

[_store requestAccessToEntityType:EKEntityTypeEvent
                       completion:^(BOOL granted, NSError *error) {
 //Handle the response here…
//Note: If you prompt the user, make sure to call the main thread


Since you can only request access once, you’ll need to test for the current authorization status first. We decided to create our own status flags that correspond with Event Kit’s then call authorizationStatus.

/// \brief Proxy for EKAuthorizationStatus in iOS 6
enum SKEKAuthorizationStatus {
    SKEKAuthorizationStatusNotDetermined = 0,

/// \brief Helper method checks the authorization
/// \return If running in iOS 6 or higher returns the EKAuthorizationStatus; otherwise, returns SKEKAuthorizationStatusAuthorized
- (enum SKEKAuthorizationStatus) authorizationStatus {
    if ([[EKEventStore class] respondsToSelector: @selector(authorizationStatusForEntityType:)]) {
        return [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
    else {
        return SKEKAuthorizationStatusAuthorized;

If calendar access was denied before (SKEKAuthorizationStatusDenied), then we prompt the user to enable access by tapping Settings > Privacy > Calendars > Skedi. If permission is undetermined (SKEKAuthorizationStatusNotDetermined), then we instantiate the EKEventStore and request access. If previously granted access, we can safely alloc and init without a care.

So, I hope this helps anyone who is currently working on adapting their Event Kit code for iOS 6. Let me know if you have any feedback.

How to configure TextMate’s SQL bundle on Mac OS X Snow Leopard

TextMate is a great text editor for Macs. Its supports a myriad of programming and scripting languages. However, after I installed it. I was unable to get the SQL bundle to work properly on Mac OS X (10.6.x) or Snow Leopard. I blew it off for a while. Then I found this post by 豆皮儿.

The post says to replace the keychain and plist bundles in TextMate’s application bundle. Instead of using the command line, I recommend these steps:

  1. Go to http://svn.textmate.org/trunk/Support/lib/osx
  2. Download keychain.bundle and plist.bundle.
  3. In the Finder window, navigate to /Applications/TextMate.app and right-click Show Package Contents.
  4. Navigate to /Contents/SharedSupport/Support/lib/osx.
  5. From your downloads directory, drag the new keychain and plist bundles to the osx directory.
  6. Open TextMate, configure the SQL bundle (SQL > Preferences) and test a query such as “SELECT 1;”

That’s it. Enjoy.

Installing the APR-based Tomcat Native library and enabling SSL

Tomcat 6.x can be turbo-charged by using the Apache Portable Runtime (APR).

The Apache Portable Runtime is a highly portable library that is at the heart of Apache HTTP Server 2.x. APR has many uses, including access to advanced IO functionality (such as sendfile, epoll and OpenSSL), OS level functionality (random number generation, system status, etc), and native process handling (shared memory, NT pipes and Unix sockets). –Apache Tomcat User Guide

The Tomcat native library requires the following three components:

  • APR Library
  • JNI wrappers for APR used by Tomcat (libtcnative)
  • OpenSSL libraries
  1. Download and install the APR 1.4.x library and follow the README instructions. For Mac OS X, I used the following commands from this article.
    # Configure the make file from the download directory
    # Users of 64-bit Java 6 should use the following configure command:
    CFLAGS='-arch x86_64' ./configure
    # Make the library
    # Test the build (Takes a while)
    make test
    # Install APR
    make install
  2. Compile and install the Tomcat native library in the bin directory. Detailed instructions here. For Mac OS X, I used the following commands from this article.
    # Build the make file for Java 5
    ./configure --with-apr=/usr/local/apr --with-ssl=/usr # With SSL
    ./configure --with-apr=/usr/local/apr --without-ssl # Without SSL
    # Some have reported having to use the --with-java-home option even with Java 5
    ./configure --with-apr=/usr/local/apr --with-ssl=/usr --with-java-home=/System/Library/Frameworks/JavaVM.framework/Versions/1.5 # With SSL
    ./configure --with-apr=/usr/local/apr --without-ssl --with-java-home=/System/Library/Frameworks/JavaVM.framework/Versions/1.5 # Without SSL
    # Users of 64-bit Java 6 should use the following configure command:
    CFLAGS='-arch x86_64' ./configure --with-apr=/usr/local/apr --with-ssl=/usr/ssl --with-java-home=/System/Library/Frameworks/JavaVM.framework/Versions/1.6
    # Make
  3. Install the OpenSSL libraries (if necessary), more details here. It’s already installed on Mac OS X and distributions of Linux.

Okay, if you’re new to OpenSSL, here’s where the missing manual comes in. For testing or development, create self-signed certificates as follows:

openssl req -new -newkey rsa:1024 -nodes -out <tomcat home>conf/ssl/ca/localhost.csr -keyout <tomcat home>conf/ssl/ca/localhost.key

Then create a X.509 certificate:

openssl x509 -trustout -signkey <tomcat home>conf/ssl/ca/ca.key -days 365 -req -in <tomcat home>conf/ssl/ca/localhost.csr -out <tomcat home>conf/ssl/ca/localhost.pem

Edit the context.xml file in the conf directory (<tomcat home>conf). See Tomcat’s SSL documentation for more details.

<!-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 -->
<Connector protocol="org.apache.coyote.http11.Http11AprProtocol"
 port="8443" maxThreads="200"
 scheme="https" secure="true" SSLEnabled="true"

Shutdown and start Tomcat and you should see the following line:
INFO - Loaded APR based Apache Tomcat Native library 1.1.16.

I hope helps you smoothly transition to the Tomcat native library.

One Piece of Advice from Seven Investors

This is a belated live blog post for the Early Stage VC and Angle Investor Event I attended yesterday in downtown Seattle. The event was organized by FundingPost and sponsored by Perkins Coie LLP.

In afternoon, Ben Straughan a partner at Perkins Coie, moderated a panel discussion with the following VC/angel investors:

  • Petra Franklin, Managing Director, Vault Capital
  • Bill McAleer, Managing Director, Voyager Capital
  • Cathi Hatch, Founder and CEO, ZINO Society
  • Janis Machala, Founder and Managing Partner, Paladin Partners
  • Lucinda Stewart, Managing Director, OVP Venture Partners
  • Bill Bryant, Venture Partner, Draper Fisher Jurvetson
  • Saqib Rasool, CEO and Angel Investor, Conceivian

For their background and expertise, check out their bios here.

There was a lot of useful information, especially for new entrepreneurs and folks considering approaching angel investors. I’m not going to rehash the event. Instead I’m going to focus on one question asked by Ben Straughan: “If you had one thing to say to these entrepreneurs, what would it be?”

Here’s their paraphrased responses from my notes:

Pick a good partner. ― Petra Franklin

Persistence and focus. ― Bill McAleer

Listen to your investors. ― Cathi Hatch

Why you? Why are you born to do this? ― Janis Machala

Find two to three CEOs to coach you. ― Lucinda Stewart

It’s about the team. ― Bill Bryant

Raise the least amount possible, build your product fast and keep your budget low. ― Saqib Rasool

Good advice indeed and for those of us with limited resources, Saqib Rasool’s point could be a daily scrum for CEOs:

  • Are we raising the least amount possible?
  • Are we building the product as fast as we can?
  • Are we keeping our budget low?

Do you have any advice to share?

Tip: MySQL Table Naming Across Platforms

If your MySQL development and production environments are Mac OS X or Windows, queries containing all lowercase or uppercase table names will work fine. This is because these platforms are case-insensitive. However, if you deploy to a Unix system, queries referencing table names in the incorrect case will not work. Consequently, adopting a standard naming convention across platforms is the best policy. I decided to go with all lowercase with underscores between words (my_table_name).

For more information here’s a post by Craig Buckler on sitepoint.com.

RESTful Serialization with Flexjson

XML is too fat for a mobile RESTful API. Therefore, I’m using JavaScript Object Notation (JSON) to exchange data between mobile devices and a cloud service I’m developing. My server environment is J2EE-based, so I chose Flexjson to serialize Java object fields as JSON. This post is a quick overview of my implementation and a lesson learned.

Flexjson is a lightweight Java library that enables object filtering during serialization. If you have a complex object model, serializing the entire object graph is undesirable. Flexjson allows you to pick and choose which objects or fields to serialize.

Here’s simple example of excluding a password field in serialized JSON.

String result =
         new JSONSerializer().
         exclude("password").serialize("user", this);
Client's JSON result
   "user": {
   "class": "com.mycompany",
   "email": "somebody@email.com",
   "firstName": "John",
   "lastName": "Doe",
   "phone": "555-1212"

The shallow deserialization is limited to: String, Date, Number, Boolean, Character, Enum, Object and null. Subclasses of Object will be serialized except for Collection or Arrays. Consequently, if the deserializer is unable to construct the object, an exception will be thrown.

All objects are built using an ObjectFactory during deserialization and each object must have a constructor that takes no arguments. Users can write their own factories and the library comes with many factories for types such as bytes, characters, dates, and so on. However, an integer object factory is nonexistent. Here’s mine:

public class IntObjectFactory implements ObjectFactory {

	/* (non-Javadoc)
	 * @see flexjson.ObjectFactory#instantiate(flexjson.ObjectBinder,

	public Object instantiate(ObjectBinder context,
                                  Object value,
                                  Type targetType,
                                  Class targetClass) {
		 if( value instanceof Number ) {
	            return ((Number)value).intValue();
	        } else {
	            throw context.

It was so easy to write, I’m not sure why is wasn’t included in the shipped version.

Lastly, here’s how to use the factory during deserialization:

JSONDeserializer<Map<String, List<SomeObject>>> deserializer =
       new JSONDeserializer<Map<String, List<SomeObject>>>();

Map<String, List<SomeObject>> members =
       new IntObjectFactory()).deserialize(returnValue);

For more info check out the Flexjson home page here: http://flexjson.sourceforge.net/