Observing Changes to Apple iCal Events

I have a Mac OS X application observing changes to iCal events. Tip: To learn how do this check out Apple’s Calendar Store Programming Guide.

I wrote the initial application as a Command Line Tool. However, the observer was not being notified.

Here’s my lesson, ensure that your application is a Cocoa Application to receive notifications from the framework.


Observing Changes to Apple iCal Events

Testing a Network Connection on the iPhone

If your iPhone app needs to test for a network connection, try this code out:

#import <SystemConfiguration/SystemConfiguration.h>
#import <netinet/in.h>

+ (BOOL) connectedToNetwork
	// Create zero addy
	struct sockaddr_in zeroAddress;
	bzero(&zeroAddress, sizeof(zeroAddress) ) ;
	zeroAddress. sin_len = sizeof(zeroAddress) ;
	zeroAddress. sin_family = AF_INET;
	// Recover reachability flags
	SCNetworkReachabilityRef defaultRouteReachability =
	SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr*) &zeroAddress) ;
	SCNetworkReachabilityFlags flags;
	BOOL didRetrieveFlags =
	SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags) ;
	CFRelease(defaultRouteReachability) ;
	if (!didRetrieveFlags)
		printf(" Error. Could not recover network reachability flags\n") ;
		return 0;
	BOOL isReachable = flags & kSCNetworkFlagsReachable;
	BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
	return (isReachable && !needsConnection) ? YES : NO;
Source: Sadun, E. (2009). The Iphone developer’s cookbook : building mobile applications with the iphone sdk. Crawfordsville, IN: Pearson Education.
Testing a Network Connection on the iPhone

Developing an ActiveMQ C++ JMS Client for Mac OS X

I’m switching gears in this post to discuss my experience with installing and integrating Apache ActiveMQ’s C++ client library with Objective-C. ActiveMQ is an open-source message broker, for Windows and UNIX, from the Apache Software Foundation.

Topics covered:

  • Intro to ActiveMQ
  • Installing ActiveMQ C++ Client Libraries
  • Integrating ActiveMQ C++ with Objective-C

In previous posts, I cover iPhone development topics for a prototype I’m working on. Yet, my iPhone app is only one client in a larger software as a service (SaaS) prototype. The plan is to have the SaaS system support clients across other popular mobile platforms and desktop operating systems such as Mac OS X and Windows.

In this heterogeneous computing environment, some of my components need to reliably send and receive messages. So, adding a message broker to the mix makes sense. However, for a prototype, buying a commercial product such as IBM’s WebSphere MQ is out-of-the-question. Consequently, I chose Apache ActiveMQ.

Apache ActiveMQ is an open source message broker which fully implements the Java Message Service 1.1 (JMS). It provides “Enterprise Features” like clustering, multiple message stores, and availability to use any database as a JMS persistence provider besides VM, cache, and journal persistency.

Apart from Java, ActiveMQ can be also used from .NET, C/C++ or Delphi or from scripting languages like Perl, Python, PHP and Ruby via various “Cross Language Clients” together with connecting to many protocols and platforms.

Apache ActiveMQ. (2009, November 26). In Wikipedia, The Free Encyclopedia. Retrieved 23:00, November 26, 2009, from http://en.wikipedia.org/w/index.php?title=Apache_ActiveMQ&oldid=328100430

Installing ActiveMQ is easy. Writing Java clients is straightforward. However, I have a native Mac OS X client (written in Objective-C) that needs to process messages. Fortunately, ActiveMQ has a C++ client library or CMS, which stands for C++ Messaging Service; and since Xcode supports Objective C++ (mixing Objective-C and C++) I have a solution for integrating my client with ActiveMQ.

Installing CMS on a UNIX-based system is not as easy as installing the ActiveMQ server. There are some hoops to jump through.

  1. Download CMS here.
  2. Follow the README instructions and note that the package is dependent on number of tools and libraries:
    • autoconf version >= 2.61
    • automake version >= 1.10
    • libtool version >= 1.5.24
    • APR version >= 1.3
    • APR-Util version >= 1.3
    • CPPUnit version >= 1.10.2*
    • libuuid version >= ?*

On Mac OS X 10.6.x, I already had autoconf, automake, and libtool. But, I had to install the latter four packages before installing CMS. Each installation follows the same set of standard command lines, check the requisite README for variations:

  • ./configure
  • make
  • make [test or check]
  • make install

After installing everything, the CMS libraries will be in usr/local/lib and ready to use in Xcode.

Moving to client development, I had the simple CMS consumer example running straightaway. However, once I began to mix in my Objective-C code, my build was wrought with pre-complier errors of the form: expected ‘;’, ‘,’ or ‘)’ before ‘>’ token.

Answers to this issue on the web were illusive. But, I knew the root cause was the inclusion of <Foundation/Foundation.h> with my C++. Fiddling with build settings was futile. My workaround, remove all references to Foundation.h and explicitly add only the headers the implementation needs. For example: <Foundation/NSString.h>, <Foundation/NSDate.h>, <Foundation/NSDateFormatter.h>Works like a charm, but tedious. I wish Xcode had a command analogous to Organize Imports in Eclipse.

In any case, my ActiveMQ Objective C++ client is now working nicely. I hope this info helps some other Xcoder out there.

Developing an ActiveMQ C++ JMS Client for Mac OS X

Some Cocoa Touch Tips, Not Tricks

I’ve made significant progress on my prototype iPhone app since my last post. I’m continuing to learn something new during each coding session. This post contains my learning nuggets and a few code snippets that I hope you’ll find useful.

Table View Development

I’m developing a productivity app, so it makes heavy use of UIKit’s UITableView classes. Here’s a few key things to remember as you develop your UITableViewController.

    1. Set a table cell’s text elements from your model in thecellForRowAtIndexPath method
    2. Set a cell’s row height by implementing the heightForRowAtIndexPath method
    3. Change the appearance of a cell’s label text (textLabel and detailedTextLabel) by setting the corresponding property.

cell.textLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];
cell.textLabel.textColor = [UIColor grayColor];
  1. Respond to row selections in the didSelectRowAtIndexPath method. The code for inclusive and exclusive selection is in Apple’s iPhone Table View Programming guide here.

Manipulating Dates

Displaying dates requires the use of the NSDateFormatter class.

  1. Avoid learning the hard way, case matters in your date format strings, e.g., yyyy-MM-dd. Here’s a good post that covers the problem.
  2. Computing dates (or what Apple refers to as calendrical calculations) is a bit too verbose from me. Here’s how to calculate the top of the hour.

NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

NSDateComponents *minutesComponent = [gregorian components:NSMinuteCalendarUnit fromDate:today];
NSDateComponents *secondsComponent = [gregorian components:NSSecondCalendarUnit fromDate:today];

NSDateComponents *componentsToSubtract = [[NSDateComponents alloc] init];
[componentsToSubtract setMinute:0 - [minutesComponent minute] ];
[componentsToSubtract setSecond:0 - [secondsComponent second] ];

NSDate *topOftheHour = [gregorian dateByAddingComponents:componentsToSubtract toDate:today options:0];

Internet Access

For applications accessing internet resources, here’s a few tidbits:

  • To indicate network activity, it’s easy to add spinner or UIActivityIndicatorView to a view. However, if the main thread is too busy, it will not appear.
  • The result of a URL connection (or NSURLConnection) is a binary NSData object, convert it to a string by invoking initWithData in NSString.
  • Parsing JSON objects is a breeze with the JSON Framework for Objective-C. By the way, for server-side Java, check out Flexjson, works like a charm.

Parsing Newlines

Is parsing newlines as simple as searching for “\n”? No, take a gander at this code from Apple’s documentation:

- (NSMutableArray *) parseRawString: (NSString *) rawString  {
	int unsigned length = [rawString length];
	int unsigned paraStart = 0, paraEnd = 0, contentsEnd = 0;
	NSMutableArray *array = [NSMutableArray array];
	NSRange currentRange;
	while (paraEnd < length) {
	      [rawString getParagraphStart:&paraStart end:&paraEnd contentsEnd:&contentsEnd forRange:NSMakeRange(paraEnd, 0)];
	      currentRange = NSMakeRange(paraStart, contentsEnd - paraStart);
	      [array addObject:[rawString substringWithRange:currentRange]];
	return array;

Lastly, Google search and stackoverflow are your friends. If you get stuck, Google it, you’ll most likely find the answer in stackoverflow or the iPhone Dev SDK forum. (However, always read Apple’s iPhone programming guides first).

Well,that’s all I have for now, happy programming!

Some Cocoa Touch Tips, Not Tricks

My iPhone Development Bootcamp

I’m working on a mobile software business idea with a friend. My close friends and professional contacts like the idea. Their advice, build a working prototype to show potential customers and investors.

My immediate platform choice, iPhone OS. But, I’m a C++ and Java guy and native iPhone apps are built using Objective-C and the Cocoa Touch API. So, I was I need of some fast-track training, ASAP.

How did I learn Objective-C? To be clear, Objective-C and C++ are quite different. But, if you are comfortable with C++, these are useful references:

Note: Objective-C is object oriented (OO). Therefore, familiarity with OO is a must.

What about Cocoa Touch? Every budding iPhone developer starts at Apple’s iPhone Development Center, which has a lot of learning content. For me, I prefer learning by seeing, hearing and doing. So, I began with the Getting Starting videos, which are split into easily digestible twenty minute chunks. Except for the last one “The Fundamentals of Cocoa” which is over an hour of yawning.

The videos are a good a high-level overview and helpful in determining which areas to pursue further. However, for more in-depth study, I highly recommend Stanford University’s iPhone development course on iTunes U.

My learning workflow was ideal:

  • Watch a lecture
  • Practice in Xcode
  • Develop the associated component

Learning and developing my prototype at the same time, beautiful. Thank you iTunes U and Stanford!

In my next post, I’ll discuss how I broke through coding roadblocks.


My iPhone Development Bootcamp

How Do You Mockup Your iPhone App Designs

I’ve been working on a mobile software business idea with a friend. It looks great on paper and feedback has been positive. Yet, investors will need to see it in action. So, I set out to design a smartphone prototype, specifically for the iPhone OS.

Initially, I drew mockups with pencil and paper. With paper-wads piling up; I was in need of a better way. Yahoo’s design stencils look great. However, a cryptic error message from OmniGraffle’s installer put a premature end to my product review.

After more poking around the internet, I found Balsamiq Mockups. I began using it straight away. I like it because it helps me to focus on design and usability instead of product features. I also find that it enhances discussions with my stakeholders because I believe the informal look of the drawings encourage more constructive feedback and design ideas.

What’s your favorite mockup tool?


How Do You Mockup Your iPhone App Designs

Is my iPhone App a Commodity?

According to this article by Robert Scoble, a recent release of Tweetie is under scrutiny for charging a fee for an upgrade in the App store. What’s going on here?
In early May 2009, Mashable compares 29 Twitter apps for the iPhone. I assume there’re more today. An excess supply of iPhone Twitter apps suggests falling prices.
If I were a budding iPhone Twitter app developer, I would ask the following the questions when considering price and positioning:
  • What’s the perception of quantity or choice from the consumer’s perspective?
  • Are Twitter apps affected by commoditization? Are there too many Twitter apps in the App Store?
  • How will I differentiate my product?
  • How will I get users to trade up to other products or services?

In the interest of full disclosure, I’ve had an iPhone for less than a week and don’t own Tweetie 2.

Is my iPhone App a Commodity?

Having Trouble with a Bonjour for Windows Printer Connection

My Airport Extreme is setup, painless on Macs, but vexing on Windows. Why? Blame an elusive printer connection.

In the Bonjour Printer Wizard, this error:

“You do not have sufficient access to your computer to connect to the selected printer.” Um yeah…(imagine Office Space manager)…not so fast. “I’m gonna need you to come in on Saturday.”

No worries, this tech note describes the problem and how to fix it.

Having Trouble with a Bonjour for Windows Printer Connection

My Snow Leopard Mail is Back to Normal

Yesterday I tweeted that I was having issues with Mac Mail after installing Snow Leopard. Well, everything is functioning normally now.

What was the problem?

My wife figured out that my outgoing SMTP server changed for a few of my email accounts and the change was not reflected in my settings. She updated my accounts and voila, everything’s back to normal. Moreover, because I’m using MobileMe sync, these changes were immediately replicated to my other Mac. Beautiful, thanks honey!

My Snow Leopard Mail is Back to Normal