EMLocalNotificationManager.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // EMLocalNotificationManager.h
  3. // LocalNotification
  4. //
  5. // Created by lixiaoming on 2021/8/24.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import <UserNotifications/UserNotifications.h>
  9. NS_ASSUME_NONNULL_BEGIN
  10. typedef NS_ENUM(NSInteger, EMNotificationState) {
  11. EMWillPresentNotification = 0,
  12. EMDidReceiveNotificationResponse
  13. };
  14. /**
  15. * \~chinese
  16. * 本地消息通知相关的代理协议。
  17. *
  18. * \~english
  19. * The callbacks of chat message notification.
  20. */
  21. @protocol EMLocalNotificationDelegate <NSObject>
  22. @optional
  23. /**
  24. * \~chinese
  25. * 当应用在前台收到推送通知,此方法会被调用
  26. * 通过completionHandle(UNNotificationPresentationOptions options)回调展示样式,必须回调
  27. *
  28. *
  29. * \~english
  30. *
  31. * This method will be called when application receives notification in the foreground.
  32. * By completionHandle (UNNotificationPresentationOptions options) callback display style, must be the callback.
  33. *
  34. */
  35. - (void)emuserNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler;
  36. /**
  37. * \~chinese
  38. * 当用户打开应用推送通知时,此方法会被调用
  39. * completionHandler必须回调
  40. *
  41. * \~english
  42. *
  43. * This method will be called when user open application notification.
  44. * CompletionHandler must be called back
  45. *
  46. */
  47. - (void)emuserNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler;
  48. /**
  49. * \~chinese
  50. * 在应用启动时被调用,以响应用户查看应用内通知设置的请求
  51. *
  52. * \~english
  53. *
  54. * The method will be called on the delegate when the application is launched in response to the user's request to view in-app notification settings
  55. *
  56. */
  57. - (void)emuserNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification;
  58. /**
  59. * \~chinese
  60. * 获取推送消息 可只实现这个代理方法统一获取推送通知消息
  61. *
  62. * \~english
  63. *
  64. * Getting push messages can be implemented only with this delegate method to uniformly get notification messages
  65. *
  66. */
  67. - (void)emGetNotificationMessage:(UNNotification*)notification state:(EMNotificationState)state;
  68. /**
  69. * \~chinese
  70. * 当应用收到环信推送透传消息时,此方法会被调用
  71. *
  72. * \~english
  73. *
  74. * This method is called when the application received easemob push silent message
  75. *
  76. */
  77. - (void)emDidRecivePushSilentMessage:(NSDictionary *)messageDic;
  78. @end
  79. /**
  80. * \~chinese
  81. * 管理本地消息通知的类。
  82. *
  83. * \~english
  84. * A class that manages the chat message notification.
  85. */
  86. @interface EMLocalNotificationManager : NSObject
  87. /**
  88. * \~chinese
  89. * 分配内存。
  90. *
  91. * \~english
  92. * Allocs.
  93. */
  94. +(instancetype _Nonnull ) alloc __attribute__((unavailable("call sharedManager instead")));
  95. /**
  96. * \~chinese
  97. * 创建实例。
  98. *
  99. * \~english
  100. * Create an instance.
  101. */
  102. +(instancetype _Nonnull ) new __attribute__((unavailable("call sharedManager instead")));
  103. /**
  104. * \~chinese
  105. * 复制实例。
  106. *
  107. * \~english
  108. * Copy an instance.
  109. */
  110. -(instancetype _Nonnull ) copy __attribute__((unavailable("call sharedManager instead")));
  111. /**
  112. * \~chinese
  113. * 复制并生成新的实例。
  114. *
  115. * \~english
  116. * Copy and generate a new instance.
  117. */
  118. -(instancetype _Nonnull ) mutableCopy __attribute__((unavailable("call sharedManager instead")));
  119. /**
  120. * \~chinese
  121. * 创建当前类的实例。
  122. *
  123. * \~english
  124. * Create an instance.
  125. */
  126. + (instancetype _Nonnull )sharedManager;
  127. /**
  128. * \~chinese
  129. * 启用本地消息通知功能。
  130. *
  131. * 启用后该功能后,新消息会出现在通知栏中,方便用户即时阅读,提升用户体验。
  132. *
  133. * \~english
  134. *
  135. * Enables the chat message notification service.
  136. *
  137. * Once you enable this service, the new message is reported in the notification bar so that users can read them in time.
  138. *
  139. */
  140. - (void)launchWithDelegate:(id<EMLocalNotificationDelegate>)aDelegate;
  141. /**
  142. * \~chinese
  143. * 如果用户在app层设置了UNUserNotificationCenterDelegate,需要在delegate实现中调用此方法
  144. * 如果不想sdk执行回调,则不传completionHandler
  145. *
  146. * \~english
  147. *
  148. * User should call this method in the implementation of UNUserNotificationCenterDelegate if they have override UNUserNotificationCenterDelegate in-app.
  149. * If you don't want the SDK to execute the callback, don't pass the completionHandler
  150. *
  151. */
  152. - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler;
  153. /**
  154. * \~chinese
  155. * 系统收到推送通知时,点击通知栏时触发的回调方法。
  156. * 如果用户在 app 层设置了 UNUserNotificationCenterDelegate,需要在 delegate 实现中调用此方法。
  157. *
  158. *
  159. * \~english
  160. * When the system receives a push notification, the callback method is triggered when the notification bar is clicked.
  161. * User should call this method in the implementation of UNUserNotificationCenterDelegate if they have override UNUserNotificationCenterDelegate in-app.
  162. *
  163. */
  164. - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler;
  165. @end
  166. NS_ASSUME_NONNULL_END