Adding A Version Check System Into A Cocoa App

Discussion in 'Mac Programming' started by Soulstorm, Apr 9, 2007.

  1. macrumors 68000


    Feb 1, 2005
    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?
  2. macrumors 6502

    Mar 31, 2005
    London, England
    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.
  3. thread starter macrumors 68000


    Feb 1, 2005
    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?
  4. macrumors 6502a

    Dec 12, 2005
    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)
  5. macrumors 68000


    Jul 7, 2006
    Queensland, Australia
    get sparkle. It is a cocoa updating system (framework really) that uses appcasts
  6. macrumors 6502

    Mar 31, 2005
    London, England
    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.
  7. macrumors 6502

    Mar 31, 2005
    London, England
  8. macrumors G4


    Nov 3, 2005
    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.

    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.

    Attached Files:

  9. Moderator emeritus


    Jun 15, 2000
    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 :)
  10. macrumors 601


    Jan 6, 2004
    Western US
    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.
  11. Guest


    Feb 17, 2003
    Hitchin, Herts, UK
    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.

Share This Page