
显示通知工作正常,以及当用户通过点击通知或通过单击 *** 作按钮与通知进行交互时,我们收到回调.
但是,当用户点击通知中的其他按钮时,我们有兴趣获取回调或事件.我看到MAC OS在显示其更新可用对话框时执行此 *** 作.
有关OS X更新可用警报的说明,请参阅此图片:
我已经通过互联网进行了搜索,并且也通过了通知中心的文档this和this.
有没有未记录的API?或一些定制机制检测点击其他(关闭)按钮?
解决方法 而另一个(关闭)按钮显然是为了解除通知,无论其自定义标题可能表示什么,当用户通过点击关闭按钮关闭通知时,没有任何优雅的方式通知.然而,您可以做的是监控默认用户通知中心的deliverNotifications属性:只要通知尚未被忽略,该数组将包含该通知.一旦通知被关闭,该阵列将不再包含它.
这可以在NSUserNotificationCenter委托方法中实现,如下所示:
- (voID)userNotificationCenter:(NSUserNotificationCenter *)center dIDDeliverNotification:(NSUserNotification *)notification{ dispatch_async(dispatch_get_global_queue(disPATCH_QUEUE_PRIORITY_DEFAulT,0),^{ BOol notificationStillPresent; do { notificationStillPresent = NO; for (NSUserNotification *nox in [[NSUserNotificationCenter defaultUserNotificationCenter] deliverednotifications]) { if ([nox.IDentifIEr isEqualToString:notification.IDentifIEr]) notificationStillPresent = YES; } if (notificationStillPresent) [NSThread sleepForTimeInterval:0.20f]; } while (notificationStillPresent); dispatch_async(dispatch_get_main_queue(),^{ [self notificationHandlerForNotification:notification]; }); });} 该代码将检查每200毫秒通知是否仍然存在.一旦消失,-notificationHandler:方法将在主线程上调用,这只是一个任意的回调方法.
在这个custom -notificationHandler:方法中,您可以检查NSUserNotificationCenter是否已经为通知调用了dIDActivateNotification:delegate方法.如果没有,用户最有可能点击通知的关闭按钮.
然而,这并不是故障安全的,因为用户也可以另外关闭通知,即不点击关闭按钮.
总结以上是内存溢出为你收集整理的objective-c – Mac OS X NSUserNotificationCenter通知取消关闭事件/回调全部内容,希望文章能够帮你解决objective-c – Mac OS X NSUserNotificationCenter通知取消关闭事件/回调所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)