Category Archives: Xcode

Hip Shot 1.0 Available on iTunes

I’m very proud to say that my latest iOS project is available on iTunes. I’ve been working with several great friends on this project for a few months now, and I think it has turned out well.

The app is called Hip Shot, and is designed for MS sufferers. Many who suffer from MS self-inject medication and must rotate through a set of locations across the body to minimize negative reactions. These folks also have the need to share that history with their nurses and neurologists. Hip Shot helps users keep track of previous injection locations, suggests coming injection locations, and allows for easy review and sharing of history.

I was approached by my good friend Zack last year about the project. He’d been diagnosed with MS and wasn’t happy with the apps already available. He put together a set of requirements and I set to work with the intention of writing an app and donating the proceeds.

I was lucky to get another friend and colleague, Al Sevajian, to help with some truly great graphics for the app. The app could have been pretty dull given the concept, but I think the professional graphics Al came up with are just top notch. My buddy Greg was also kind enough to put together a simple website for the app.

Hip Shot has been great to work on. While I’ve done a few iOS projects in the past, this is the first time I’ve done something I’d consider graphical, working with all of the different file resolutions for iPhone vs iPad vs Retina iPad. It was also my first submission directly to iTunes (my previous iOS work has been for other clients). Also, Hip Shot gave me an excuse to learn both Core Data and about synchronizing data with iCloud.

So far the feedback from users has been great, and word is slowly spreading both among users and medical personnel. As proceeds come in from Apple I’ll be making donations to the National MS Society. You can learn more at hipshotapp.com.

Delay Applying Updates in Data Abstract iOS Apps

Even though the code generated by the Data Abstract for Xcode template for iOS apps is mostly asynchronous, you may notice delays in the UI when applying updates to your server. If you check out the asyncRequest:didFinishApplyingChangesForTables:withErrors: method in DataAccess.m, you’ll see that, once an asynchronous request finishes, your data will be saved to the local briefcase file:

- (void)asyncRequest:(DAAsyncRequest *)request didFinishApplyingChangesForTables:(NSArray *)tables withErrors:(NSArray *)errors
{
	[self saveData];
	[self setBusy:NO];
...

This happens on the main thread and, given a large enough set of data, will cause your app to stutter.

Luckily this is pretty straight forward to address. Cocoa makes it easy enough to run code in a background thread, and that’s exactly what Alexander from RemObjects suggests:

-(void)saveDataInBackground {</pre>
    [self performSelectorInBackground:@selector(saveData) withObject:nil];
}

- (void)asyncRequest:(DAAsyncRequest *)request didFinishApplyingChangesForTables:(NSArray *)tables withErrors:(NSArray *)errors
{
    [self saveDataInBackground];
    [self setBusy:NO];
...

I’ve been using a form of the above solution for a while now and can confirm that things are running smoothly, even with a larger set of data. Alexander let me know that this would be addressed in the Xcode templates for a future DA update.

Offline Mode with Data Abstract for Xcode

Offline Mode Sample App

Data Abstract for Xcode makes it simple to support disconnected n-tier iPhone applications. The briefcase support is a snap, requiring only a few extra lines to be uncommented from the templates installed into Xcode by the Data Abstract installer.

I recently looked into adding support for an “offline” mode to a Data Abstract application I’ve been developing for the iPhone. Basically, the application should function whether the iOS device has an active network connection or not. If there is no connection, any changes to data should be cached until a network connection becomes available.

This ended up being pretty easy to do. I started by adding Reachability support to the application. You can read detailed instructions about how to do that on Stack Overflow.

Once Reachability support has been added, it’s trivial to alter the beginApplyUpdates code in DataAccess.m to only apply updates when a network connection is available:

- (DAAsyncRequest *)beginApplyUpdates
{
	if (!internetActive) {
		return nil;
	}
        ...
}

Then, modify the Reachability usage to apply any unsaved updates when a connection becomes available:

		case ReachableViaWiFi:
		case ReachableViaWWAN: {
			NSLog(@"The internet is working via WIFI.");
			internetActive = YES;
			//have we received data before?
			if (self.daTestTable) {
				//setup data adapter (to get a new connection)
				[self setupDataAdapter];
				//commit any pending changes to the server
				[self beginApplyUpdates];
			}

			break;
		}

The only tricky bit I found was the need to re-create the DARemoteDataAdapter after a network connection becomes available. This is because you may have an old connection that will cause an error if you try to reuse it.

You can download a sample application here. The archive includes a SQL script for generating the sample DB table.