JMessage.h 11 KB

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