Monday, August 24, 2009

[iPhone firstApp] - Getting closer to pushing out my first public app!

It's been a wild week getting my newest creation ready for the App Store. Only two more components to build for my app, and these should be quick, then up, up and away!

I've been using most new iPhone 3.0 SDK features for this app, and I have to say that I'm loving them! Core Data, MapKit and more, they've all been a blast to work with.

Here's a few screenshots of my new app, named Follow Me Photo (for now anyway). I'm excited to get it up on the App Store, and I've had wonderful support from my Wife and friends. (My kids could care less, but hey, they're teenagers!)

Hope you enjoy!

--Patrick

Tuesday, August 18, 2009

[iPhone MapKit] Controlling a MKMapView added in Interface Builderapp

Way back in December of 2008 I started dreaming about what kind of app I'd like to try and create for the iPhone, and ultimately I came down to something that would fit my love of travel and photography. And one of the areas that has given me quite a bit of a headache was around how to integrate a map with my app.

What was the sticking point? Well, it had to do with my desire to include some sort of mapping data, or better yet a map, in the app itself. Back in December, this was a huge task, and much larger than I had ever thought. At the time the MapKit didn't exist, so you were left with trying to do a huge amount of work in force fitting some other map technology into a view. Granted, many people have done that, and there are some great apps out there that do exactly that, in fact I use one myself (WeatherBug) which uses Microsoft's Virtual Earth.

About half way through my process of working on getting some sort of map integrated with my app, Apple comes out and announces the 3.0 SDK, which included an API to the mapping application, conveniently called MapKit. During the beta time, not many people had used MapKit, and initially it was all hard coded code. In fact, there's a great tutorial on this at the objectgraph.blog that I highly recommend.

Using the Interface Builder MKMapView Object
When using the objectgraph.blog tutorial, you'll probably notice that he's adding the map programatically. This is due to the fact that the early SDK betas did not include an Interface Builder object. So you had to create your MKMapView via code, then add it to a view to display.

Well, I didn't really want my map to take up the whole view, I'd rather have it be a smaller part of my overall view, so the IB object works great as I can visually size the map on my screen.

So I went into IB and designed this layout:

Then hopping back over to XCode, I attempted to wire it up so that I could control it. This proved to be a much larger headache that I had thought. Using the examples I had found I started by declaring a MapView in my interface code:

MKMapView *mapView;

...
...

@property (nonatomic, retain) IBOutlet MKMapView *mapView;


Then in my implementation code I tried to connect to the map view by doing this:

- (void)viewDidLoad {

mapView = [[MKMapView alloc] init];


Which if you try, you'll quickly learn, this doesn't work...

After going over all the examples I could find, and realizing eventually that all these folks were using the MapKit before IB had an object, I finally figured out what the problem was.

By assigning my IBOutlet to a new allocated object, I effectively broke my connection to the map. Since I declared this as a property and @synthesize it, that work was being done for me, and I could just start using it right away.

Here's my final viewDidLoad method which sets a few options for the map, and also configures some of the other parts as well...

- (void)viewDidLoad {

// set the current location lable to blank strings (will be populated later...)

currentLocationLabel.text = @"";

currentHeightLabel.text = @"";

reverseGeocodeLabel.text = @"";

// setup the mapView options

[mapView setMapType:MKMapTypeSatellite];

[mapView setZoomEnabled:YES];

[mapView setScrollEnabled:YES];

// initalize the location manager

self.locationManager = [[CLLocationManager alloc] init];

locationManager.delegate = self;

locationManager.desiredAccuracy = kCLLocationAccuracyBest;

[super viewDidLoad];

}

And finally, the running app with a working map:

Technology@ - A beginning

Hello Blogosphere!

This isn't my first venture into the void, however hopefully this will be one of my adventures that stick.

Over the last ten months I had been floating in a void of unemployment due to a very sad story involving the small start-up company I had worked for from mid 2005. In October of '08, it shut it's doors (or rather, one of the financial institutions that had a small loan with this company, shut the doors for us) and I found myself looking for a job in one of the worst economies in recent (and not so recent) history.

I quickly learned that while Unemployment truly sucks, there were some benefits and it allowed me to pick up a new "hobby" in the development (or attempt at) of iPhone applications. I've always enjoyed picking up a new programming language and giving it a whirl, and I wasn't quite blind when it came to the iPhone, I had given Mac OS X Cocoa programming a whirl on and off for a few years. Objective-C messaging and syntax wasn't a shock as I think it has been for many other developers out there, and who can really argue that the iPhone platform isn't the coolest, hottest and most exciting development platform on planet Earth today? So since I had a lot of free time on my hands, I decided to pick it up and give it a whirl.

What I hope to blog about here is some of my experiences around the iPhone development process, in various libraries, techniques and coding styles I've developed with along my journey. I can say that while the iPhone 3.x SDK is super exciting, it has also been super frustrating for me as I had an app that was all set to go (as it was) until 3.x started to show up, then I realized how much I could benefit, and then to my horror how much re-work I would have in order to get it up to 3.x specs. (So much horror in fact that I more or less gave up for a few months.) But needless to say, I've been playing with the 3.x SDK once again and I've found my sea legs once again and I'm more excited than I was back in December of '08 (and hoping to get my first app out to the public very soon!)

I guess this brings me to my reasons for writing this blog. One, for my own documentation. I've been playing with controls that, at least back in the 2.x SDK world, were discussed by other bloggers/coders/developers as not working together well in the Interface Builder and that the common knowledge was that you had to hard code the interactions of all these various controls, which ended up being pretty time consuming. Since I believe that if a company provides a tool, which has the power and simplicity of Interface Builder, you should be able to use it to do your job, and a job I thought was pretty simple *if* you only knew how to use it. As it turned out, I found the little "secret" (which I'm not sure is a secret, but no-one else seemed to know the process) behind nesting tab bar and navigation controllers graphically in IB. And most recently I've been struggling with the MapKit and using a MKMapView item from IB in my app. The good news is I've found the way around these issues and now I feel compelled to share with others.

So my first post (after this one) will be around the MapKit, and I hope you other iPhone developers will find something useful from my experiences!

Oh! One last note (not that anyone will actually read this first post) I'm a very big proponent on feedback. Please leave your thoughts if you liked/disliked/hated/loved/etc any post here. I'd love to hear from anyone and everyone that reads my ramblings!

Thanks for viewing!
--Patrick Holt