You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

notificationimpl.mm 1.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "notificationimpl.h"
  2. #include <QDebug>
  3. @interface NotificationImpl () <NSUserNotificationCenterDelegate>
  4. @end
  5. @implementation NotificationImpl
  6. -(instancetype)init
  7. {
  8. self = [super init];
  9. if(self)
  10. {
  11. id=0;
  12. [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
  13. }
  14. return self;
  15. }
  16. -(long)show:(NSString*)title message:(NSString*)msg extra:(NSString*)who
  17. {
  18. NSUserNotification* notification = [[NSUserNotification alloc] init];
  19. notification.title = title;
  20. if (who != nil && who.length > 0)
  21. {
  22. notification.userInfo=@{@"extra":who};
  23. notification.hasReplyButton = true;
  24. }
  25. int myid = ++id;
  26. notification.identifier = [NSString stringWithFormat:@"%d",myid];
  27. notification.informativeText = msg;
  28. [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notification];
  29. return (long)myid;
  30. }
  31. -(void)hideAll
  32. {
  33. [[NSUserNotificationCenter defaultUserNotificationCenter] removeAllDeliveredNotifications];
  34. }
  35. -(BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresent:(NSUserNotification *)notification
  36. {
  37. return YES;
  38. }
  39. -(void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
  40. {
  41. NSString* who = [notification.userInfo objectForKey:@"extra"];
  42. int myid = notification.identifier.intValue;
  43. if (notification.activationType == NSUserNotificationActivationTypeContentsClicked){
  44. clickCallback(callbackArg, who);
  45. }
  46. else if (notification.activationType == NSUserNotificationActivationTypeReplied){
  47. replyCallback(callbackArg, myid, who, notification.response.string);
  48. }
  49. }
  50. @end

mac下的“飞秋”大多数只是飞鸽传书协议,而且未发现令人满意的开源项目,所以基于c++与qt实现了基础的飞秋协议。

Contributors (1)