Search code examples
xcodemacosdesktop-applicationupdatessparkle

Initialise Sparkle (OS X) with appcast URL


I'm using the Sparkle framework to ship updates for my OS X desktop application. To be able to point Sparkle to different systems (staging/production), I overwrite the appcast URL entry in the Info.plist file and save the updated file to disc whenever I want the URL to change. This has the drawback that it does not become effective immediately but I have to restart the app in order for Sparkle to use the updated entry in the plist file.

Question: I did not find any resources on whether or not it is possible to pass an appcast URL to Sparkle on initialisation, so that it doesn't look for the URL loaded from the plist file before. Can anyone help on this one?


Solution

  • It really was that simple:

    // InitSparkle.mm
    
    #include "InitSparkle.h"
    
    #import <Cocoa/Cocoa.h>
    #import <AppKit/AppKit.h>
    #import <Sparkle/Sparkle.h>
    
    
    SUUpdater* suupdater = NULL;
    
    
    void initSparkle(const char* feedUrl)
    {
      suupdater = [[SUUpdater sharedUpdater] retain];
      [suupdater setAutomaticallyChecksForUpdates:YES];
      suupdater.feedURL = [NSURL URLWithString:[NSString stringWithUTF8String:feedUrl]];
      [suupdater checkForUpdates:NULL];
    }
    

    Just put the feed's URL into the SUUpdater object.