我有这样的密码。
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];此外,我还实现了userNotificationCenter:shouldPresentNotification:.效果很好。然而。当应用程序的窗口没有聚焦时,这个委托方法就不会被调用,并且通知总是会出现。
有什么帮助吗?
发布于 2014-01-10 10:41:41
首先,应该在发送-deliverNotification:消息之前设置委托。如果不这样做,那么您的委托方法可能不会被触发,即使它应该被触发。
其次,在-userNotificationCenter:shouldPresentNotification:中,它声明:
userNotificationCenter:shouldPresentNotification: 当用户通知中心决定不提交通知时,发送给委托。
也就是说,只有当NSUserNotificationCenter已经决定不显示通知时,才会看到此方法被调用。如果它已经决定要展示它,它就不会费心去问了。
https://stackoverflow.com/questions/20844497
复制相似问题