如何构建在Mac OS 10.6上运行并支持NSUserNotificationCenter的应用程序? [英] How to build an app that runs on Mac OS 10.6 and supports the NSUserNotificationCenter?

查看:95
本文介绍了如何构建在Mac OS 10.6上运行并支持NSUserNotificationCenter的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了很多研究,但我找不到我要找的:
目前,部署目标我的应用程序的基本SDK 设置为 10.8 ,它运行完美。我可以正确地将通知发布到Mountain Lions新的通知中心!

I did a lot of research but I just couldn't find what I'm looking for: Currently, both the Deployment Target and 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!

建立一个也在Mac OS下运行的应用程序 10.6 ,我已将部署目标设置为10.6并构建它(如本线程中推荐的)。不幸的是,应用程序在10.6崩溃,崩溃报告详细说明未找到NSUserNotificationCenter(无操作系统版本处理)。

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).

-

所以我肯定要做的是检查NSUserNotificationCenter类是否存在:

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:


  • 接口 :< NSUserNotificationCenterDelegate> { c>

  • 或通知中心参考类型: NSUserNotificationCenter * center 属性?

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

我的第一个想法是在运行时动态更改类标题,即添加方法和属性来处理Notificaion Center基于类是否存在,但是这看起来真的很复杂?

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 ?!

推荐答案

这些都是编译问题,所有的时候Base SDK是10.8。 center 指针可以保留在 nil 如果 NSUserNotificationCenter 存在,因此您可以使用该标记作为标记,以检查您是否在测试后在代码运行中执行通知。

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 doing notifications or not in code run after the test.

EDIT 其实离开它 nil 将意味着你甚至不需要检查它;只是正常发送消息,如果指针 nil (这是除非消息的创建是昂贵的,并且您想要保存一些CPU周期,它们将被忽略)。

EDIT 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).

这篇关于如何构建在Mac OS 10.6上运行并支持NSUserNotificationCenter的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆