Here’s a super-simple way to gently remind your users that a new version of your app is available.
Ping A Server
All you need to do is put a php (or similar) file somewhere on your site that echos the current version. When your app launches, it retrieves the bundle version, pings the server to get the latest version and compares it. The sample code below displays an alert but you can do whatever you like of course.
Server-Side
The code on the server couldn’t be simpler (actually, it could; as a commenter pointed out, it could be a .txt file that just contains the version string). All it has to do is echo the current version (store this in a file called getversion.php):
<?php echo "1.2.3"; ?>
App-Side
The app is only slightly more involved as it has to be the one to do the work.
First, you need to ping the server and get the response:
NSString * getLatestVersionFromServer(void) { NSString * server_response = nil; NSURL * web_addr = [NSURL URLWithString: @"http://www.mysite.com/myappversion/getversion.php"]; if (web_addr) { server_response = [NSString stringWithContentsOfURL:web_addr encoding:NSUTF8StringEncoding error:nil]; } return(server_response); }
Then wherever you want to do the check in your app (probably near the start), you can do it like so:
NSString * app_version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]; NSString * server_version = getLatestVersionFromServer(); if (nil != server_version) { if (NSOrderedSame != [app_version compare:server_version]) { UIAlertView * alert; alert = [[[UIAlertView alloc] initWithTitle: @"Update Available" message: [NSString stringWithFormat: @"You are running an old version of MyApp (%@).\n\nThere is a newer version available (%@).\n\nPlease consider updating.", app_version, server_version] delegate: self cancelButtonTitle: @"OK" otherButtonTitles: NULL] autorelease]; [alert show]; } }
The Result
The code is Airplane Mode safe. The key for supporting that is the check to make sure the server version is not nil (it will be if the server can’t be pinged for whatever reason).
Here is what the above code looks like when it triggers (assuming the “Bundle version” entry in the info plist is set to 1.1.1):
So there you have it. A quick and easy way to gently remind your customers to stay current.
Enjoy!