OS X:如何在点击通知中心的项目时获取userinfo?

时间:2015-08-13 00:59:11

标签: macos apple-push-notifications nsusernotification nsusernotificationcenter

由于点击通知中心的远程通知项目,我想在激活应用时执行一些特定操作。哪个代表会给userinfo?

- 的Manoj

1 个答案:

答案 0 :(得分:0)

我将继续并假设您的意思是UI通知。

您正在寻找的是NSUserNotification / NSUserNotificationCenter,而不是NSNotification / NSNotificationCenter,它们用于向您的应用程序中的对象发送消息。

您可以使用userInfo属性构建NSUserNotification,其中包含您希望稍后收到的任何信息。您可以通过访问defaultUserNotificationCenter,然后使用之前创建的通知调用-scheduleNotification:-deliverNotification:来安排NSUserNotificationCenter上的通知。最后,NSUserNotificationCenter具有delegate属性,您可以将其指定为要接收通知的任何对象。然后,该对象必须实现NSUserNotificationCenterDelegate协议中的一种方法,例如-userNotificationCenter:didDeliverNotification: