OS X:当从通知中心点击一个项目时如何获取用户信息



我想做一些特定的动作,当应用程序被激活,因为从通知中心点击远程通知项目。哪个委托会给用户信息?

——Manoj

我假设你指的是UI通知。

你要找的是NSUserNotification/NSUserNotificationCenter,而不是NSNotification/NSNotificationCenter,后者用于向应用程序中的对象发送消息。

你可以用userInfo属性构造一个NSUserNotification,其中包含你以后想要接收的任何信息。通过访问NSUserNotificationCenter上的defaultUserNotificationCenter,然后使用之前创建的通知调用-scheduleNotification:-deliverNotification:来调度通知。最后,NSUserNotificationCenter有一个delegate属性,你可以将它分配给任何你想要接收通知的对象。然后该对象必须实现NSUserNotificationCenterDelegate协议上的一个方法,例如-userNotificationCenter:didDeliverNotification:

最新更新