11.7 Lösung: Für Notifikationen registrieren
Wir wollen mit der Registrierung und der Verarbeitung von Startnotifikationen beginnen:
Notication/HelloApplication4/CurrentApp.m
-(void) registerNotifications { NSNotificationCenter *defaultCenter = [[NSWorkspace sharedWorkspace] notificationCenter]; [defaultCenter addObserver:self ▸ selector:@selector(applicationDidLaunch:) ▸ name:NSWorkspaceDidLaunchApplicationNotification object:nil]; }
Der Hauptunterschied besteht darin, dass wir den Namen der gewünschten Notifikation angeben, statt über nil
alle Notifikationen abzufangen. Ich habe darüber hinaus den Namen der Callback-Methode in applicationDidLaunch:
geändert.
Wenn ich dem gleichen Muster folge, um Beendigungsnotifikationen abzufangen und auf diese ...
Get Cocoa-Programmierung now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.