PDA

View Full Version : Adding A Version Check System Into A Cocoa App




Soulstorm
Apr 9, 2007, 04:15 AM
I have made an application written in Cocoa, and I would like to implement a function to check wether there is a newer version of my program available on the internet or not.

I have already a personal web spase available. So, my question is: what can I do to add this function, what frameworks or Cocoa classes must I use, and what method should I try to implement?



Nutter
Apr 9, 2007, 04:24 AM
There are several days of doing this. The way I'd do it is to put an XML file on your web space containing details of the latest version and a link to the download page, and load this file each time your app launches.

This is very easy to do with NSDictionary's dictionaryWithContentsOfURL: class method.

Soulstorm
Apr 9, 2007, 04:27 AM
XML.. hm... I hadn't thought of that. But I really don't know what is XML exactly, or how to use it. Have you got any guide or online documentation to give me? And why XML? Why not a simple text file?

semaja2
Apr 9, 2007, 05:03 AM
Please do us a favour and dont create your own system, if you want one use Sparkle or Sparkle Plus

It is VERY easy to implement and if more people use such a system then it is easier for other apps to come along and do a whole system update (Instead of using sites like MacUpdate)

People also are familiar with Sparkle (Adium, etc)

tominated
Apr 9, 2007, 05:20 AM
get sparkle. It is a cocoa updating system (framework really) that uses appcasts

Nutter
Apr 9, 2007, 05:35 AM
As others have said, Sparkle looks good, and does all the hard work for the user. However, there's no harm in doing it the way I said, and it's good to know how.

You could use a simple text file, but an XML file essentially lets you serialise a dictionary object that contains the version number, download URL and any other information that you need (including details of pirated registration codes if you want!). This makes it easy for your app to parse the information, because the XML format is already understood by the foundation classes.

In fact, an XML file IS just a text file, just with special tags to give it a property-value structure. You can create an XML file with any text editor, or (more easily) using Property List Editor.

This is worth looking into - knowing a bit about property lists is a pretty essential skill for a Cocoa developer.

Nutter
Apr 9, 2007, 05:40 AM
Property List Programming Guide for Cocoa (http://developer.apple.com/documentation/Cocoa/Conceptual/PropertyLists/index.html#//apple_ref/doc/uid/10000048i)

Eraserhead
Apr 9, 2007, 06:54 AM
Sparkle Plus (http://ironcoder.org/blog/2006/06/14/sparkle-plus/) looks good, I think I might give it a try in my application (I currently use Sparkle), but that's for a later point, anyhow Sparkle support is really easy to add once you've mastered writing the XML for the RSS feed it's pretty easy. Why reinvent the wheel with your own system?

Anyway Sparkle can be downloaded here (http://sparkle.andymatuschak.org/).

My RSS feed (Appcast) that I use with Sparkle is attached to this post, feel free to modify it for your own purposes, (though I'm not responsible if it doesn't work.). Though there is pretty good documentation in the download for sparkle itself that took the longest to figure out.

Note that to get it to work you'll need to remove the .txt extension and just call it appcast.xml.

kainjow
Apr 9, 2007, 01:38 PM
XML.. hm... I hadn't thought of that. But I really don't know what is XML exactly, or how to use it. Have you got any guide or online documentation to give me? And why XML? Why not a simple text file?

XML describes data in a file. Writing your own text file format is just redoing XML. If you don't know XML, go to the library and pick up a book on it, and then come back here and download Sparkle :)

HiRez
Apr 9, 2007, 10:10 PM
Sparkle looks good but just in case you wanted to keep it really simple, here is some old code I wrote to just check a text file. I put it in my app controller's +initialize method. It's very crude, but it works. All that's in the file is simply the version number, that's it.+ (void)initialize {
/* first check for new version (will be nil if no active internet connection) */
NSString *latestVersionString = [NSString stringWithContentsOfURL:RB_NEKOTESTER_VERSION_URL];
if (latestVersionString != nil && ![latestVersionString isEqualToString:@""] && ![latestVersionString isEqualToString:RB_NEKOTESTER_READABLE_VERSION]) {
int choice = 0;
NSString *msg = [NSString stringWithFormat:@"There appears to be a newer version (%@) of NekoTester available for download. Most likely it's better than this mangy old code. Would you like to get it now?", latestVersionString];
choice = NSRunAlertPanel(@"New Version Available!", msg, @"Get It Now", @"Later", nil);
if (choice == 1) {
/* get now (open download URL and quit) */
[[NSWorkspace sharedWorkspace] openURL:RB_NEKOTESTER_DOWNLOAD_URL];
[NSApp terminate:nil];
} else if (choice == 0) {
/* get later (do nothing, continue execution) */
}
}
}EDIT: removed some unimportant lines from the code.

caveman_uk
Apr 10, 2007, 02:43 AM
One nice thing (amongst the many) about Sparkle is that it handles beta versions well. So if you're beta testers are using say 1.4b2 but the appcast says the latest version is 1.4, Sparkle knows 1.4b2 is later than 1.4 and doesn't give the 'new version' message to the beta testers.