JMessage.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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/JMSGConstants.h>
  13. #import <JMessage/JMSGUser.h>
  14. #import <JMessage/JMSGGroup.h>
  15. #import <JMessage/JMSGMessage.h>
  16. #import <JMessage/JMSGConversation.h>
  17. #import <JMessage/JMSGAbstractContent.h>
  18. #import <JMessage/JMSGMediaAbstractContent.h>
  19. #import <JMessage/JMSGCustomContent.h>
  20. #import <JMessage/JMSGEventContent.h>
  21. #import <JMessage/JMSGImageContent.h>
  22. #import <JMessage/JMSGTextContent.h>
  23. #import <JMessage/JMSGVoiceContent.h>
  24. #import <JMessage/JMessageDelegate.h>
  25. #import <JMessage/JMSGFileContent.h>
  26. #import <JMessage/JMSGFriendManager.h>
  27. #import <JMessage/JMSGNotificationEvent.h>
  28. #import <JMessage/JMSGFriendNotificationEvent.h>
  29. #import <JMessage/JMSGLocationContent.h>
  30. #import <JMessage/JMSGPromptContent.h>
  31. #import <JMessage/JMSGOptionalContent.h>
  32. #import <JMessage/JMSGChatRoom.h>
  33. #import <JMessage/JMSGConstants.h>
  34. @protocol JMSGMessageDelegate;
  35. @protocol JMessageDelegate;
  36. @class JMSGConversation;
  37. extern NSString *const kJMSGNetworkIsConnectingNotification; // 正在连接中
  38. extern NSString *const kJMSGNetworkDidSetupNotification; // 建立连接
  39. extern NSString *const kJMSGNetworkDidCloseNotification; // 关闭连接
  40. extern NSString *const kJMSGNetworkDidRegisterNotification; // 注册成功
  41. extern NSString *const kJMSGNetworkFailedRegisterNotification; // 注册失败
  42. extern NSString *const kJMSGNetworkDidLoginNotification; // 连接成功
  43. extern NSString *const kJMSGNetworkDidReceiveMessageNotification; // 收到消息
  44. extern NSString *const kJMSGServiceErrorNotification; // 错误提示
  45. /*!
  46. * JMessage核心头文件
  47. *
  48. * 这是唯一需要导入到你的项目里的头文件,它引用了内部需要用到的头文件。
  49. */
  50. @interface JMessage : NSObject
  51. /*! JMessage SDK 版本号。用于展示 SDK 的版本信息 */
  52. #define JMESSAGE_VERSION @"3.5.0"
  53. /*! JMessage SDK 构建ID. 每次构建都会增加 */
  54. #define JMESSAGE_BUILD 210
  55. /*! API Version - int for program logic. SDK API 有变更时会增加 */
  56. extern NSInteger const JMESSAGE_API_VERSION;
  57. /*!
  58. * @abstract 初始化 JMessage SDK
  59. *
  60. * @discussion 此方法被[JMessage setupJMessage:appKey:channel:apsForProduction:category:messageRoaming:]方法取代
  61. */
  62. + (void)setupJMessage:(NSDictionary *)launchOptions
  63. appKey:(NSString *)appKey
  64. channel:(NSString *)channel
  65. apsForProduction:(BOOL)isProduction
  66. category:(NSSet *)category __attribute__((deprecated("JMessage 3.1.0 版本已过期")));
  67. /*!
  68. * @abstract 初始化 JMessage SDK
  69. *
  70. * @param launchOptions AppDelegate启动函数的参数launchingOption(用于推送服务)
  71. * @param appKey appKey(应用Key值,通过JPush官网可以获取)
  72. * @param channel 应用的渠道名称
  73. * @param isProduction 是否为生产模式
  74. * @param category iOS8新增通知快捷按钮参数
  75. * @param isRoaming 是否启用消息漫游,默认关闭
  76. *
  77. * @discussion 此方法必须被调用, 以初始化 JMessage SDK
  78. *
  79. * 如果未调用此方法, 本 SDK 的所有功能将不可用.
  80. */
  81. + (void)setupJMessage:(NSDictionary *)launchOptions
  82. appKey:(NSString *)appKey
  83. channel:(NSString *)channel
  84. apsForProduction:(BOOL)isProduction
  85. category:(NSSet *)category
  86. messageRoaming:(BOOL)isRoaming;
  87. /*!
  88. * @abstract 增加回调(delegate protocol)监听
  89. *
  90. * @param delegate 需要监听的 Delegate Protocol
  91. * @param conversation 允许为nil
  92. *
  93. * - 为 nil, 表示接收所有的通知, 不区分会话.
  94. * - 不为 nil,表示只接收指定的 conversation 相关的通知.
  95. *
  96. * @discussion 默认监听全局 JMessageDelegate 即可.
  97. *
  98. * 这个调用可以在任何地方, 任何时候调用, 可以在未进行 SDK
  99. * 启动 setupJMessage:appKey:channel:apsForProduction:category: 时就被调用.
  100. *
  101. * 并且, 如果你有必要接收数据库升级通知 JMSGDBMigrateDelegate,
  102. * 就应该在 SDK 启动前就调用此方法, 来注册通知接收.
  103. * 这样, SDK启动过程中发现需要进行数据库升级, 给 App 发送数据库升级通知时,
  104. * App 才可以收到并进行处理.
  105. */
  106. + (void)addDelegate:(id <JMessageDelegate>)delegate withConversation:(JMSGConversation *)conversation;
  107. /*!
  108. * @abstract 删除Delegate监听
  109. *
  110. * @param delegate 监听的 Delegate Protocol
  111. * @param conversation 基于某个会话的监听. 允许为 nil.
  112. *
  113. * - 为 nil, 表示全局的监听, 即所有会话相关.
  114. * - 不为 nil, 表示特定的会话.
  115. */
  116. + (void)removeDelegate:(id <JMessageDelegate>)delegate withConversation:(JMSGConversation *)conversation;
  117. /*!
  118. * @abstract 删除全部监听
  119. */
  120. + (void)removeAllDelegates;
  121. /*!
  122. * @abstract 打开日志级别到 Debug
  123. *
  124. * @discussion JMessage iOS SDK 默认开启的日志级别为: Info. 只显示必要的信息, 不打印调试日志.
  125. *
  126. * 调用本接口可打开日志级别为: Debug, 打印调试日志,初始化 SDK 前调用.
  127. */
  128. + (void)setDebugMode;
  129. /*!
  130. * @abstract 关闭日志
  131. *
  132. * @discussion 关于日志级别的说明, 参考 [JMessage setDebugMode]
  133. *
  134. * 虽说是关闭日志, 但还是会打印 Warning, Error 日志. 这二种日志级别, 在程序运行正常时, 不应有打印输出.
  135. *
  136. * 建议在发布的版本里, 调用此接口, 关闭掉日志打印.
  137. */
  138. + (void)setLogOFF;
  139. /*!
  140. * @abstract 注册远程推送
  141. * @param types 通知类型
  142. * @param categories 类别组
  143. * @discussion 此方法必须被调用,如果有集成JPush或其他远程推送注册方法,请不要再调用此方法
  144. *
  145. */
  146. + (void)registerForRemoteNotificationTypes:(NSUInteger)types categories:(NSSet *)categories;
  147. /*!
  148. * @abstract 注册 DeviceToken
  149. * @param deviceToken 从注册推送回调中拿到的 DeviceToken
  150. * @discussion 此方法必须被调用
  151. *
  152. */
  153. + (void)registerDeviceToken:(NSData *)deviceToken;
  154. /*!
  155. * @abstract 验证此 appKey 是否为当前应用 appKey
  156. *
  157. * @param appKey
  158. *
  159. * @return 是否为当前应用 appKey
  160. */
  161. + (BOOL)isMainAppKey:(NSString *)appKey;
  162. /*!
  163. * @abstract 设置角标(到服务器)
  164. *
  165. * @param value 新的值. 会覆盖服务器上保存的值(这个用户)
  166. *
  167. * @discussion 本接口不会改变应用本地的角标值.
  168. * 本地仍须调用 UIApplication:setApplicationIconBadgeNumber 函数来设置脚标.
  169. *
  170. * 该功能解决的问题是, 服务器端推送 APNs 时, 并不知道客户端原来已经存在的角标是多少, 指定一个固定的数字不太合理.
  171. *
  172. * APNS 服务器端脚标功能提供:
  173. *
  174. * - 通过本 API 把当前客户端(当前这个用户的) 的实际 badge 设置到服务器端保存起来;
  175. * - 调用服务器端 API 发 APNs 时(通常这个调用是批量针对大量用户),
  176. * 使用 "+1" 的语义, 来表达需要基于目标用户实际的 badge 值(保存的) +1 来下发通知时带上新的 badge 值;
  177. */
  178. + (BOOL)setBadge:(NSInteger)value;
  179. /*!
  180. * @abstract 重置角标(为0)
  181. *
  182. * @discussion 相当于 [setBadge:0] 的效果.
  183. * 参考 [JMessage setBadge:] 说明来理解其作用.
  184. */
  185. + (void)resetBadge;
  186. /*!
  187. * @abstract 发送透传消息给自己在线的其他设备
  188. *
  189. * @param message 发送的内容
  190. * @param platform 设备类型
  191. * @param handler 回调
  192. *
  193. * @discussion 注意:
  194. *
  195. * 1. 消息透传功能,消息不会进入到后台的离线存储中去,仅当对方用户当前在线时才会成功送达,SDK 不会将此类消息内容存储;
  196. *
  197. * 2. 透传命令到达是,接收方通过 [JMSGEventDelegate onReceiveMessageTransparentEvent:] 方法监听。
  198. *
  199. * @since 3.5.0
  200. */
  201. + (void)sendCrossDeviceTransMessage:(NSString *)message
  202. platform:(JMSGPlatformType)platform
  203. handler:(JMSGCompletionHandler)handler;
  204. /*!
  205. * @abstract 判断是否设置全局免打扰
  206. *
  207. * @return YES/NO
  208. */
  209. + (BOOL)isSetGlobalNoDisturb;
  210. /*!
  211. * @abstract 设置是否全局免打扰
  212. *
  213. * @param isNoDisturb 是否全局免打扰 YES:是 NO: 否
  214. * @param handler 结果回调。回调参数:error 不为 nil,表示设置失败
  215. *
  216. * @discussion 此函数为设置全局的消息免打扰,建议开发者在 SDK 完全启动之后,再调用此接口获取数据
  217. */
  218. + (void)setIsGlobalNoDisturb:(BOOL)isNoDisturb handler:(JMSGCompletionHandler)handler;
  219. /*!
  220. * @abstract 用户免打扰列表
  221. *
  222. * @param handler 结果回调。回调参数:
  223. *
  224. * - resultObject 类型为 NSArray,数组里成员的类型为 JMSGUser、JMSGGroup
  225. * - error 错误信息
  226. *
  227. * 如果 error 为 nil, 表示设置成功
  228. * 如果 error 不为 nil,表示设置失败
  229. *
  230. * @discussion 从服务器获取,返回用户的免打扰列表。
  231. * 建议开发者在 SDK 完全启动之后,再调用此接口获取数据
  232. */
  233. + (void)noDisturbList:(JMSGCompletionHandler)handler;
  234. /*!
  235. * @abstract 黑名单列表
  236. *
  237. * @param handler 结果回调。回调参数:
  238. *
  239. * - resultObject 类型为 NSArray,数组里成员的类型为 JMSGUser
  240. * - error 错误信息
  241. *
  242. * 如果 error 为 nil, 表示设置成功
  243. * 如果 error 不为 nil,表示设置失败
  244. *
  245. * @discussion 从服务器获取,返回用户的黑名单列表。
  246. * 建议开发者在 SDK 完全启动之后,再调用此接口获取数据
  247. */
  248. + (void)blackList:(JMSGCompletionHandler)handler;
  249. /*!
  250. * @abstract 获取当前服务器端时间
  251. *
  252. * @discussion 可用于纠正本地时间。
  253. */
  254. + (NSTimeInterval)currentServerTime;
  255. /*!
  256. * @abstract 发起数据库升级测试
  257. *
  258. * @discussion 这是一个专用于测试时使用到的接口.
  259. *
  260. * 关于数据库升级相关, 参考这个 [JMSGDBMigrateDelegate] 类里的说明.
  261. *
  262. * 调用此接口后, App 会收到一个升级开始通知, 30s 后再收到一个升级结束通知.
  263. *
  264. * 本接口内部并不会真实地发起数据库升级操作, 而仅用于发出开始与完成的通知, 以方便 App 来测试处理流程.
  265. */
  266. + (void)testDBMigrating;
  267. @end
  268. /*!
  269. * 用户登录设备信息
  270. */
  271. @interface JMSGDeviceInfo: NSObject
  272. /// 设备所属平台,Android、iOS、Windows、web
  273. @property(nonatomic, assign, readonly) JMSGPlatformType platformType;
  274. /// 是否登录,YES:已登录,NO:未登录
  275. @property(nonatomic, assign, readonly) BOOL isLogin;
  276. /// 是否在线,0:不在线,1:在线
  277. @property(nonatomic, assign, readonly) UInt32 online;
  278. /// 上次登录时间
  279. @property(nonatomic, strong, readonly) NSNumber *mtime;
  280. /// 默认为0,1表示该设备被当前登录设备踢出
  281. @property(nonatomic, assign, readonly) NSInteger flag;
  282. @end