NSNotification Problem unter Mavericks

  • NSNotification Problem unter Mavericks

    Hallo zusammen,
    wenn ich in der init-Methode einer NSView diesen Code habe:

    Quellcode

    1. [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
    2. selector:@selector(receiveLaunching:)
    3. name:NSWorkspaceWillLaunchApplicationNotification
    4. object:nil];


    dann stürzt das Programm, beim Aufrufen dieser Notification ab, Begründung: EXS_BAD_ACCES.
    Das passiert bei jeden Notification.
    Wenn ich stattdessen diesen Code verwende:

    Quellcode

    1. [[NSNotificationCenter defaultCenter] addObserver:self
    2. selector:@selector(receiveLaunching:)
    3. name:NSWorkspaceWillLaunchApplicationNotification
    4. object:nil];


    dann kommt zwar keine Fehlermeldung, aber die receiveLaunching-Methode wird auch nicht aufgerufen!
    Das ganze programmiere ich unter Mavericks, unter SnowLeopard hatte es prima funktioniert (Ich bleibe SL-Fan... <3).
    Hat jemand ähnliche Erfahrung oder eine Lösung? Mach ich einen Fehler?
    Danke im voraus!
    Osxer
  • @Thallius: Nein, ganz so stur bin ich nicht! Ich habe mich auf Manfred bezogen. Ich habe beide Möglichkeiten ausprobiert, und beide funktionieren nicht!!

    Quellcode

    1. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    2. {
    3. NSNotificationCenter *notiCenter = [NSNotificationCenter defaultCenter];
    4. [notiCenter addObserver:self
    5. selector:@selector(a:)
    6. name:NSWorkspaceDidLaunchApplicationNotification
    7. object:nil];
    8. }
    9. - (void)a:(NSNotification *)n
    10. {
    11. NSLog(@"%@",n);
    12. }
    Alles anzeigen

    Auch im AppDelegate: Geht nicht!
    Ich muss außer dem Code doch nichts machen (Framework etc.), oder? Das wäre mir neu.
  • So funktioniert es tatsächlich:

    Quellcode

    1. NSNotificationCenter *notiCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
    2. [notiCenter addObserver:self
    3. selector:@selector(a:)
    4. name:NSWorkspaceWillLaunchApplicationNotification
    5. object:nil];

    !!
    Aber, wenn ich NSWorkspaceWillSleepNotification nehme, dann kommt wieder nichts...
  • Mhm... habe es jetzt in meinem alten Projekt wieder ausprobiert, und wieder kommt EXS_BAD_ACCESS...

    Quellcode

    1. NSNotificationCenter *center = [[NSWorkspace sharedWorkspace] notificationCenter];
    2. [center addObserver:self
    3. selector:@selector(receiveSleep:)
    4. name:NSWorkspaceDidLaunchApplicationNotification
    5. object:nil];
    6. [center addObserver:self
    7. selector:@selector(receiveSleep:)
    8. name:NSWorkspaceScreensDidWakeNotification
    9. object:nil];