SUUpdaterWillRestartNotification not happening?

Asked by tornado

Hello again,

I'm very close to finishing my System Preference. Part of my bundle has a background agent application, that, when the update is about to be applied, needs to be killed. It appears from the documentation that I can add an observer of self to my system preference to listen for SUUpdaterWillRestartNotification. Once I hear that I can kill my process and let the magic happen. Problem is, my system preference never hears this notification. Here is my code. I do have other notifications so I know that I have syntax and such correct (I think).

Any assistance appreciated.
Thanks,
Joe

- (id)initWithBundle:(NSBundle *)bundle
{
.
.
.
 [nc addObserver:self selector:@selector(SUUpdaterWillRestart3:) name:SUUpdaterWillRestartNotification object:nil];
 return self;
}

- (void) SUUpdaterWillRestart3 :(NSNotification *) inNotification
{
// this method is never called......
 NSLog(@"SUUpdaterWillRestart!!!! ");
}

Question information

Language:
English Edit question
Status:
Solved
For:
Sparkle Edit question
Assignee:
No assignee Edit question
Solved by:
tornado
Solved:
Last query:
Last reply:
Revision history for this message
Andy Matuschak (andymatuschak) said :
#1

That's very curious; I suspect it's possibly due to the fact that you're a bundle in a separate host app. This may have made it so that there are multiple NSNotificationCenters floating around. I'm not sure if that's a thing.

Anyway, one easy workaround is simply to use the equivalent delegate method instead:
- (void)updaterWillRelaunchApplication;

Revision history for this message
tornado (joe-flexgames) said :
#2

Would the delegate be an option from SUUpdater? Wouldn't I just control-drag from Updater to my object and specify delegate? If so I don't have that option with my SUUpdater class. Not sure how to use that method.
Thanks.

Revision history for this message
Andy Matuschak (andymatuschak) said :
#3

Yeah, the delegate is an ivar of the SUUpdater.

Oh, good call; the delegate should be an IBOutlet but it isn't. bzr pull, and it will be, or you can just call setDelegate on the SUUpdater.

Revision history for this message
tornado (joe-flexgames) said :
#4

Andy - forgive me if this is a stupid question - I'm not very "up" on delgates, but I know you can set a delegate from an NSApplication. I'm guessing that normal NSApplications would have you control-drag from the File's Owner to the Updater Object and set delegate that way. This an NSPreferencePane that I'm writing. Can you still set SUUpdater to be a delegate from File's Owner (which again, is an NSPreferencePane)? I can't seem specify SUUpdater to be a delegate of it when I try...

Seems like I'm making this too complicated. If only I could figure out why my observer isn't observing either...

Revision history for this message
tornado (joe-flexgames) said :
#5

Reading on this a bit more, I think I am even more confused. Wouldn't I make my File's Owner (which is an instance of my Preference) a delegate of the SUUpdater instance so that I can call - (void)updaterWillRelaunchApplication; in my code? My brain is fuzzy on this... Time for sleep.

Revision history for this message
tornado (joe-flexgames) said :
#6

OK I gave it one more shot and figured it out. I needed to call

[[SUUpdater sharedUpdater] setDelegate:self];

in my mainViewDidLoad

It's now calling UpdaterWillRelaunchApplication.

Revision history for this message
Peter Speck (speck) said :
#7

Yep. It's the same method I use for stopping a daemon so it can be upgraded.