¿Cómo crear una aplicación que se ejecute en Mac OS 10.6 y sea compatible con NSUserNotificationCenter?

I did a lot of research but I just couldn't find what I'm looking for: Currently, both the Deployment Target y Base SDK of my app is set to 10.8, and it runs perfectly. I can properly post Notifications to Mountain Lions new Notification Center!

To build an app that also runs under Mac OS 10.6, I've set the Deployment Target to 10.6 and built it (as recommended in this thread). Unfortunately, the app crashes on 10.6, and the crash report is detailing that the NSUserNotificationCenter couldn't be found (No OS version handling).


So what I surely have to do, is to check, whether the NSUserNotificationCenter class exists:

notificationCenterIsAvailable = (NSClassFromString(@"NSUserNotificationCenter")!=nil);

and operate based on this boolean flag.

But what about Code that can't be based on this flag, like:

  • La interfaz ..: <NSUserNotificationCenterDelegate> {
  • or the type of the reference to the Notification Center: NSUserNotificationCenter *center in the class' properties?

My first thought was to dynamically alter the class header at runtime, i.e., add the methods and properties to handle the Notificaion Center based on whether the class exists or not, but this seems like really complex ?!

preguntado el 31 de julio de 12 a las 10:07

1 Respuestas

Those are compilation issues and will be fine all the time the Base SDK is 10.8. The center pointer can remain at nil if NSUserNotificationCenter does not exist, and you could therefore use that as a flag to check if you are "Hacer" notifications or not in code run after the test.

EDITAR In fact leaving it nil will mean you don't even need to check for it; just send messages as normal and they will be ignored if the pointer is nil (this is unless the creation of the message is expensive and you want to save some CPU cycles).

Respondido 31 Jul 12, 10:07

So even delegate methods like userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification: y (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification: are being cleared away by the compiler automatically? - Raffael

It's working, thank you! The recent crash must have had another reason. - Raffael

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.