JMessageDelegate.h 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * | | | | \ \ / / | | | | / _______|
  3. * | |____| | \ \/ / | |____| | / /
  4. * | |____| | \ / | |____| | | | _____
  5. * | | | | / \ | | | | | | |____ |
  6. * | | | | / /\ \ | | | | \ \______| |
  7. * | | | | /_/ \_\ | | | | \_________|
  8. *
  9. * Copyright (c) 2011 ~ 2015 Shenzhen HXHG. All rights reserved.
  10. */
  11. #import <Foundation/Foundation.h>
  12. #import <JMessage/JMSGMessageDelegate.h>
  13. #import <JMessage/JMSGConversationDelegate.h>
  14. #import <JMessage/JMSGGroupDelegate.h>
  15. #import <JMessage/JMSGUserDelegate.h>
  16. #import <JMessage/JMSGDBMigrateDelegate.h>
  17. #import <JMessage/JMSGEventDelegate.h>
  18. /*!
  19. * 全局代理协议
  20. *
  21. * 一般情况下, App 只需要注册这个全局代理, 则其他类别里的代理都注册到.
  22. * 由于回调方法都是可选, 你可以根据需要实现一个或者多个回调, 在你实现的方法里, 有事件时就会回调.
  23. *
  24. * #### 消息接收和发送
  25. *
  26. * 以下代码, 假设当前类是 ChatViewController, 要完成这样的功能:
  27. * 接收当前聊天所在的会话的 - 发出的消息的返回, 以及服务器端下发的消息.
  28. *
  29. * ```
  30. * // 通过你的方式取到了 Conversation 实例
  31. * JMSGConversation *theConversation = ...;
  32. *
  33. * // 在类的初始化代码里, 注册代理, 指定 Conversation.
  34. * [JMessage addDelegate:self withConversation:theConversation];
  35. *
  36. * // 实现 JMSGMessageDelegate 里的发送消息返回的回调方法
  37. * - (void)onSendMessageResponse:(JMSGMessage *)message
  38. * error:(NSError *)error {
  39. * // 这里处理发送消息返回
  40. * // message 对象是你原本发出的消息对象
  41. * }
  42. *
  43. * // 实现 JMSGMessageDelegate 里的接收消息回调方法
  44. * - (void)onReceiveMessage:(JMSGMessage *)message
  45. * error:(NSError *)error {
  46. * // 这里处理收到的消息
  47. * }
  48. * ```
  49. *
  50. * 有些特殊的消息,需要做特殊判断,比如:群里的一些事件消息,添加群成员、设置群管理员事件等.
  51. * 思路上, 需要先从 onReceiveMessage 上收到事件类型的消息, 判断 JMSGEventContent 里的
  52. * eventType = kJMSGEventNotificationAddGroupMembers 表示这是一个群组加人的事件.
  53. *
  54. * 以下示例代码在上述 onReceiveMessage 监听里:
  55. *
  56. * ```
  57. * if (message.contentType == kJMSGContentTypeEventNotification) {
  58. * JMSGEventContent *eventContent = (JMSGEventContent) message.content;
  59. * if (eventContent.eventType == kJMSGEventNotificationAddGroupMembers) {
  60. * // 一般的作法应该是界面显示一条消息: “xxx 加入了群组”
  61. * }
  62. * }
  63. * ```
  64. *
  65. * #### 事件代理
  66. *
  67. * 有一类特殊的系统事件, 需要特别提示,如:其他设备登录被踢、加好友、申请入群等事件,SDK 会收到一个下发通知.
  68. * 思路上, 需要先实现相关事件的代理方法,如果有多个事件共用同一个代理还需判断 eventType.
  69. *
  70. * 以用户被踢事件为例:
  71. *
  72. * ```
  73. * // 实现 JMSGEventDelegate 里的接收事件代理方法
  74. * - (void)onReceiveLoginUserStatusChangeEvent:(JMSGUserLoginStatusChangeEvent *)event {
  75. * if (event.eventType == kJMSGEventNotificationLoginKicked) {
  76. * // 这里做用户被踢处理. 一般的作法应该是: 弹出提示信息,告诉用户在其他设备登录了;
  77. * // 弹窗关闭后界面切换到用户登录界面
  78. * }
  79. * }
  80. * ```
  81. * 其他事件的监听类似.
  82. */
  83. @protocol JMessageDelegate <JMSGMessageDelegate,
  84. JMSGConversationDelegate,
  85. JMSGGroupDelegate,
  86. JMSGUserDelegate,
  87. JMSGDBMigrateDelegate,
  88. JMSGEventDelegate>
  89. @end