单击时显示NSUserNotification AdditionalActions [英] show NSUserNotification additionalActions on click

查看:83
本文介绍了单击时显示NSUserNotification AdditionalActions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在上图中,您可以在OS X上看到两个通知.第一个通知来自我的应用程序,第二个通知来自Apple的Reminders.app.在图像中,您可以看到otherButtonTitle完成"和actionButtonTitle以后".

In the image above you can see two notifications on OS X. The first one is from my app and the second is from Apple's Reminders.app. In the image you can see the otherButtonTitle 'Complete' and the actionButtonTitle 'Later'.

第二个通知,即来自Reminders.app的通知,其行为完全不同.它会在鼠标悬停时使这个小箭头指向下方,表示单击时还有更多操作.实际上,您只需单击稍后"上的一次,它将为您提供更多选择.

The second notification, i.e. the one from Reminders.app behaves quite differently. It gets this little arrow pointing downwards on mouse over indicating that there are more actions when clicked. And indeed, you just need to click once on 'Later' and it will give you a couple more options to choose from.

但是,对于通知,我无法获得相同的行为.我没有将鼠标悬停在小箭头上,也没有通过单击稍后"单击来显示更多选项(只是取消了通知).仅在按住"Later"(较晚)上的鼠标按钮时,才会显示更多选项.

However, I can't get the same behavior to work for my notification. I don't get the little arrow on mouse over and I don't get more options displayed from a single click on 'Later' (notification just gets dismissed). More options only get displayed when holding down the mouse button on 'Later' which is not obvious.

我在这里缺少明显的东西吗?如何获得与Reminders.app中的通知完全相同的通知?

Am I missing something obvious here? How can I get my notification to have exactly the same as the ones from the Reminders.app?

推荐答案

在尝试找到相同问题的解决方案时,我发现了NSUserNotificationPrivate类的很好解释,该类解释了Reminders应用程序的实现方式.

While trying to find a solution for the same problem I found this nice explanation for the NSUserNotificationPrivate class that explains how the Reminders app does it.

https://github.com/indragiek/NSUserNotificationPrivate

如果通知类型设置为"Alert",则alternativeActionButtonTitles属性使您可以设置要在操作菜单中显示的其他菜单项标题数组,可以通过将鼠标悬停在操作"按钮上并单击箭头来访问该菜单.

If the notification type is set to "Alert", the alternateActionButtonTitles property lets you set an array of additional menu item titles to be shown in an action menu that can be accessed by hovering on the Action button and clicking on the arrow.

一旦处理了通知,就可以使用_alternateActionIndex属性检索操作的索引.

Once a notification is handled, the index of the action can be retrieved using the _alternateActionIndex property.

因此,他们正在使用私有API.如网站的免责声明所述,使用任何一种方法都会导致您的应用程序被MAS拒绝,并且如果API发生更改,可能会导致应用程序中断.

So they are using a private API. As the site's disclaimer say using any of this will result in your app being rejected from the MAS and potentially breaking if the APIs change.

这篇关于单击时显示NSUserNotification AdditionalActions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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