XGPush.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. //
  2. // 信鸽核心接口
  3. // XG-SDK
  4. //
  5. // Created by xiangchen on 13-10-18.
  6. // Update by uweiyuan on 4/08/17.
  7. // Copyright (c) 2013年 XG. All rights reserved.
  8. //
  9. #import <Foundation/Foundation.h>
  10. #import <UIKit/UIKit.h>
  11. @class CLLocation;
  12. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  13. #import <UserNotifications/UserNotifications.h>
  14. #endif
  15. /**
  16. @brief 点击行为对象的属性配置
  17. - XGNotificationActionOptionNone: 无
  18. - XGNotificationActionOptionAuthenticationRequired: 需要认证的选项
  19. - XGNotificationActionOptionDestructive: 具有破坏意义的选项
  20. - XGNotificationActionOptionForeground: 打开应用的选项
  21. */
  22. typedef NS_ENUM(NSUInteger, XGNotificationActionOptions) {
  23. XGNotificationActionOptionNone = (0),
  24. XGNotificationActionOptionAuthenticationRequired = (1 << 0),
  25. XGNotificationActionOptionDestructive = (1 << 1),
  26. XGNotificationActionOptionForeground = (1 << 2)
  27. };
  28. /**
  29. * @brief 定义了一个可以在通知栏中点击的事件对象
  30. */
  31. @interface XGNotificationAction : NSObject
  32. /**
  33. @brief 在通知消息中创建一个可以点击的事件行为
  34. @param identifier 行为唯一标识
  35. @param title 行为名称
  36. @param options 行为支持的选项
  37. @return 行为对象
  38. @note 通知栏带有点击事件的特性,只有在iOS8+以上支持,iOS 8 or earlier的版本,此方法返回空
  39. */
  40. + (nullable id)actionWithIdentifier:(nonnull NSString *)identifier title:(nonnull NSString *)title options:(XGNotificationActionOptions)options;
  41. /**
  42. @brief 点击行为的标识
  43. */
  44. @property (nullable, nonatomic, copy, readonly) NSString *identifier;
  45. /**
  46. @brief 点击行为的标题
  47. */
  48. @property (nullable, nonatomic, copy, readonly) NSString *title;
  49. /**
  50. @brief 点击行为的特性
  51. */
  52. @property (readonly, nonatomic) XGNotificationActionOptions options;
  53. @end
  54. /**
  55. @brief 分类对象的属性配置
  56. - XGNotificationCategoryOptionNone: 无
  57. - XGNotificationCategoryOptionCustomDismissAction: 发送消失事件给UNUserNotificationCenter(iOS 10 or later)对象
  58. - XGNotificationCategoryOptionAllowInCarPlay: 允许CarPlay展示此类型的消息
  59. */
  60. typedef NS_OPTIONS(NSUInteger, XGNotificationCategoryOptions) {
  61. XGNotificationCategoryOptionNone = (0),
  62. XGNotificationCategoryOptionCustomDismissAction = (1 << 0),
  63. XGNotificationCategoryOptionAllowInCarPlay = (1 << 1)
  64. };
  65. /**
  66. * 通知栏中消息指定的分类,分类主要用来管理一组关联的Action,以实现不同分类对应不同的Actions
  67. */
  68. @interface XGNotificationCategory : NSObject
  69. /**
  70. @brief 创建分类对象,用以管理通知栏的Action对象
  71. @param identifier 分类对象的标识
  72. @param actions 当前分类拥有的行为对象组
  73. @param intentIdentifiers 用以表明可以通过Siri识别的标识
  74. @param options 分类的特性
  75. @return 管理点击行为的分类对象
  76. @note 通知栏带有点击事件的特性,只有在iOS8+以上支持,iOS 8 or earlier的版本,此方法返回空
  77. */
  78. + (nullable id)categoryWithIdentifier:(nonnull NSString *)identifier actions:(nullable NSArray<XGNotificationAction *> *)actions intentIdentifiers:(nullable NSArray<NSString *> *)intentIdentifiers options:(XGNotificationCategoryOptions)options;
  79. /**
  80. @brief 分类对象的标识
  81. */
  82. @property (nonnull, readonly, copy, nonatomic) NSString *identifier;
  83. /**
  84. @brief 分类对象拥有的点击行为组
  85. */
  86. @property (nonnull, readonly, copy, nonatomic) NSArray<XGNotificationAction *> *actions;
  87. /**
  88. @brief 可用以Siri意图的标识组
  89. */
  90. @property (nullable, readonly, copy, nonatomic) NSArray<NSString *> *intentIdentifiers;
  91. /**
  92. @brief 分类的特性
  93. */
  94. @property (readonly, nonatomic) XGNotificationCategoryOptions options;
  95. @end
  96. /**
  97. @brief 注册通知支持的类型
  98. - XGUserNotificationTypeNone: 无
  99. - XGUserNotificationTypeBadge: 支持应用角标
  100. - XGUserNotificationTypeSound: 支持铃声
  101. - XGUserNotificationTypeAlert: 支持弹框
  102. - XGUserNotificationTypeCarPlay: 支持CarPlay,iOS 10.0+
  103. - XGUserNotificationTypeCriticalAlert: 支持紧急提醒播放声音, iOS 12.0+
  104. - XGUserNotificationTypeProvidesAppNotificationSettings: 让系统在应用内通知设置中显示按钮, iOS 12.0+
  105. - XGUserNotificationTypeProvisional: 能够将非中断通知临时发布到 Notification Center, iOS 12.0+
  106. - XGUserNotificationTypeNewsstandContentAvailability: 支持 Newsstand, iOS 3.0–8.0
  107. */
  108. typedef NS_OPTIONS(NSUInteger, XGUserNotificationTypes) {
  109. XGUserNotificationTypeNone = (0),
  110. XGUserNotificationTypeBadge = (1 << 0),
  111. XGUserNotificationTypeSound = (1 << 1),
  112. XGUserNotificationTypeAlert = (1 << 2),
  113. XGUserNotificationTypeCarPlay = (1 << 3),
  114. XGUserNotificationTypeCriticalAlert = (1 << 4),
  115. XGUserNotificationTypeProvidesAppNotificationSettings = (1 << 5),
  116. XGUserNotificationTypeProvisional = (1 << 6),
  117. XGUserNotificationTypeNewsstandContentAvailability = (1 << 3)
  118. };
  119. /**
  120. @brief 管理推送消息通知栏的样式和特性
  121. */
  122. @interface XGNotificationConfigure : NSObject
  123. /**
  124. @brief 配置通知栏对象,主要是为了配置消息通知的样式和行为特性
  125. @param categories 通知栏中支持的分类集合
  126. @param types 注册通知的样式
  127. @return 配置对象
  128. */
  129. + (nullable instancetype)configureNotificationWithCategories:(nullable NSSet<XGNotificationCategory *> *)categories types:(XGUserNotificationTypes)types;
  130. - (nonnull instancetype)init NS_UNAVAILABLE;
  131. /**
  132. @brief 返回消息通知栏配置对象
  133. */
  134. @property (readonly, nullable, strong, nonatomic) NSSet<XGNotificationCategory *> *categories;
  135. /**
  136. @brief 返回注册推送的样式类型
  137. */
  138. @property (readonly, nonatomic) XGUserNotificationTypes types;
  139. /**
  140. @brief 默认的注册推送的样式类型
  141. */
  142. @property (readonly, nonatomic) XGUserNotificationTypes defaultTypes;
  143. @end
  144. /**
  145. @brief 设备token绑定的类型,绑定指定类型之后,就可以在信鸽前端按照指定的类型进行指定范围的推送
  146. - XGPushTokenBindTypeNone: 当前设备token不绑定任何类型,可以使用token单推,或者是全量推送(3.2.0+ 不推荐使用 )
  147. - XGPushTokenBindTypeAccount: 当前设备token与账号绑定之后,可以使用账号推送
  148. - XGPushTokenBindTypeTag: 当前设备token与指定标签绑定之后,可以使用标签推送
  149. */
  150. typedef NS_ENUM(NSUInteger, XGPushTokenBindType) {
  151. XGPushTokenBindTypeNone = (0),
  152. XGPushTokenBindTypeAccount = (1 << 0),
  153. XGPushTokenBindTypeTag = (1 << 1)
  154. };
  155. /**
  156. @brief 定义了一组关于设备token绑定,解绑账号和标签的回调方法,用以监控绑定和解绑的情况
  157. */
  158. @protocol XGPushTokenManagerDelegate <NSObject>
  159. @optional
  160. /**
  161. @brief 监控token对象绑定的情况
  162. @param identifier token对象绑定的标识
  163. @param type token对象绑定的类型
  164. @param error token对象绑定的结果信息
  165. */
  166. - (void)xgPushDidBindWithIdentifier:(nonnull NSString *)identifier type:(XGPushTokenBindType)type error:(nullable NSError *)error;
  167. /**
  168. @brief 监控token对象解绑的情况
  169. @param identifier token对象解绑的标识
  170. @param type token对象解绑的类型
  171. @param error token对象解绑的结果信息
  172. */
  173. - (void)xgPushDidUnbindWithIdentifier:(nonnull NSString *)identifier type:(XGPushTokenBindType)type error:(nullable NSError *)error;
  174. /**
  175. @brief 监控token对象identifiers绑定的情况
  176. @param identifiers token对象绑定的标识
  177. @param type token对象绑定的类型
  178. @param error token对象绑定的结果信息
  179. */
  180. - (void)xgPushDidBindWithIdentifiers:(nonnull NSArray *)identifiers type:(XGPushTokenBindType)type error:(nullable NSError *)error;
  181. /**
  182. @brief 监控token对象identifiers解绑的情况
  183. @param identifiers token对象解绑的标识
  184. @param type token对象解绑的类型
  185. @param error token对象解绑的结果信息
  186. */
  187. - (void)xgPushDidUnbindWithIdentifiers:(nonnull NSArray *)identifiers type:(XGPushTokenBindType)type error:(nullable NSError *)error;
  188. /**
  189. @brief 监控token对象更新已绑定标识的情况
  190. @param identifiers token对象更新后的标识
  191. @param type token对象更新类型
  192. @param error token对象更新标识的结果信息
  193. */
  194. - (void)xgPushDidUpdatedBindedIdentifiers:(nonnull NSArray *)identifiers bindType:(XGPushTokenBindType)type error:(nullable NSError *)error;
  195. /**
  196. @brief 监控清除token对象绑定标识的情况
  197. @param type token对象清除的类型
  198. @param error token对象清除标识的结果信息
  199. */
  200. - (void)xgPushDidClearAllIdentifiers:(XGPushTokenBindType)type error:(nullable NSError *)error;
  201. @end
  202. @interface XGPushTokenManager : NSObject
  203. /**
  204. @brief 创建设备token的管理对象,用来管理token的绑定与解绑操作
  205. @return 设备token管理对象
  206. @note 此类的 APIs 调用都是以 Token 在信鸽服务上完成注册为前提
  207. */
  208. + (nonnull instancetype)defaultTokenManager;
  209. - (nonnull instancetype)init NS_UNAVAILABLE;
  210. /**
  211. @brief 设备token管理操作的代理对象
  212. */
  213. @property (weak, nonatomic, nullable) id<XGPushTokenManagerDelegate> delegate;
  214. /**
  215. @brief 返回当前设备token的字符串
  216. */
  217. @property (copy, nonatomic, nullable, readonly) NSString *deviceTokenString;
  218. /**
  219. @brief 为token对象设置绑定类型和标识
  220. @param identifier 指定绑定标识
  221. @param type 指定绑定类型
  222. */
  223. - (void)bindWithIdentifier:(nonnull NSString *)identifier type:(XGPushTokenBindType)type;
  224. /**
  225. @brief 根据类型和标识为token对象解绑
  226. @param identifier 指定解绑标识
  227. @param type 指定解绑类型
  228. @note 若需要解绑全部标签,建议使用 removeAllTags: 接口
  229. */
  230. - (void)unbindWithIdentifer:(nonnull NSString *)identifier type:(XGPushTokenBindType)type;
  231. /**
  232. @brief 根据指定类型查询当前token对象绑定的标识
  233. @param type 指定绑定类型
  234. @return 当前token对象绑定的标识
  235. */
  236. - (nullable NSArray *)identifiersWithType:(XGPushTokenBindType)type;
  237. /**
  238. @brief 为token对象设置绑定类型和标识
  239. @param identifiers 指定绑定标识,标签字符串不允许有空格或者是tab字符
  240. @param type 指定绑定类型
  241. @note 对于账号操作,需要使用json数组,例如:
  242. [
  243. {"account" : "account1", "account_type" : 1},
  244. {"account" : "account2","account_type" : 0}
  245. ]
  246. 账号类型,请参照: http://xg.qq.com/docs/server_api/v3/push_api_v3.html#账号类型
  247. */
  248. - (void)bindWithIdentifiers:(nonnull NSArray *)identifiers type:(XGPushTokenBindType)type;
  249. /**
  250. @brief 根据类型和标识为token对象解绑
  251. @param identifiers 指定解绑标识,标签字符串不允许有空格或者是tab字符
  252. @param type 指定解绑类型
  253. @note 标签字符串不允许有空格或者是tab字符;对于账号操作,需要使用json数组,例如:
  254. [
  255. {"account" : "account1", "account_type" : 1},
  256. {"account" : "account2","account_type" : 0}
  257. ]
  258. 账号类型,请参照: http://xg.qq.com/docs/server_api/v3/push_api_v3.html#账号类型
  259. */
  260. - (void)unbindWithIdentifers:(nonnull NSArray *)identifiers type:(XGPushTokenBindType)type;
  261. /**
  262. @brief 根据类型,覆盖原有的标识;若之前没有绑定标识,则会执行新增标识
  263. @param identifiers 标签标识字符串数组,标签字符串不允许有空格或者是tab字符
  264. @param type 标识类型
  265. @note 若指定为标签类型,此接口会将当前 Token 对应的旧有的标签全部替换为当前的标签;若指定账号类型,对于账号操作,则需要使用json数组,例如:
  266. [
  267. {"account" : "account1", "account_type" : 1},
  268. {"account" : "account2","account_type" : 0}
  269. ]
  270. 账号类型,请参照: http://xg.qq.com/docs/server_api/v3/push_api_v3.html#账号类型
  271. */
  272. - (void)updateBindedIdentifiers:(nonnull NSArray *)identifiers bindType:(XGPushTokenBindType)type;
  273. /**
  274. @brief 根据标识类型,清除所有标识
  275. @param type 标识类型
  276. */
  277. - (void)clearAllIdentifiers:(XGPushTokenBindType)type;
  278. @end
  279. /**
  280. @brief 监控信鸽服务启动和设备token注册的一组方法
  281. */
  282. @protocol XGPushDelegate <NSObject>
  283. @optional
  284. - (void)xgPushDidReceiveRemoteNotification:(nonnull id)notification withCompletionHandler:(nullable void (^)(NSUInteger))completionHandler;
  285. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  286. /**
  287. @brief 处理iOS 10 UNUserNotification.framework的对应的方法
  288. @param center [UNUserNotificationCenter currentNotificationCenter]
  289. @param notification 通知对象
  290. @param completionHandler 回调对象,必须调用
  291. */
  292. - (void)xgPushUserNotificationCenter:(nonnull UNUserNotificationCenter *)center willPresentNotification:(nullable UNNotification *)notification withCompletionHandler:(nonnull void (^)(UNNotificationPresentationOptions options))completionHandler __IOS_AVAILABLE(10.0);
  293. /**
  294. @brief 处理iOS 10 UNUserNotification.framework的对应的方法
  295. @param center [UNUserNotificationCenter currentNotificationCenter]
  296. @param response 用户对通知消息的响应对象
  297. @param completionHandler 回调对象,必须调用
  298. */
  299. - (void)xgPushUserNotificationCenter:(nonnull UNUserNotificationCenter *)center didReceiveNotificationResponse:(nullable UNNotificationResponse *)response withCompletionHandler:(nonnull void (^)(void))completionHandler __IOS_AVAILABLE(10.0);
  300. #endif
  301. /**
  302. @brief 监控信鸽推送服务地启动情况
  303. @param isSuccess 信鸽推送是否启动成功
  304. @param error 信鸽推送启动错误的信息
  305. */
  306. - (void)xgPushDidFinishStart:(BOOL)isSuccess error:(nullable NSError *)error;
  307. /**
  308. @brief 监控信鸽服务的终止情况
  309. @param isSuccess 信鸽推送是否终止
  310. @param error 信鸽推动终止错误的信息
  311. */
  312. - (void)xgPushDidFinishStop:(BOOL)isSuccess error:(nullable NSError *)error;
  313. /**
  314. @brief 监控信鸽服务上报推送消息的情况
  315. @param isSuccess 上报是否成功
  316. @param error 上报失败的信息
  317. */
  318. - (void)xgPushDidReportNotification:(BOOL)isSuccess error:(nullable NSError *)error;
  319. /**
  320. @brief 监控设置信鸽服务器下发角标的情况
  321. @param isSuccess isSuccess 上报是否成功
  322. @param error 设置失败的信息
  323. */
  324. - (void)xgPushDidSetBadge:(BOOL)isSuccess error:(nullable NSError *)error;
  325. /**
  326. @brief 设备token注册信鸽服务的回调
  327. @param deviceToken 当前设备的token
  328. @param error 错误信息
  329. */
  330. - (void)xgPushDidRegisteredDeviceToken:(nullable NSString *)deviceToken error:(nullable NSError *)error;
  331. @end
  332. /**
  333. @brief 管理信鸽推送服务的对象,负责注册推送权限、消息的管理、调试模式的开关设置等
  334. */
  335. @interface XGPush : NSObject
  336. #pragma mark - 初始化相关
  337. /**
  338. @brief 获取信鸽推送管理的单例对象
  339. @return 信鸽推送对象
  340. */
  341. + (nonnull instancetype)defaultManager;
  342. /**
  343. @brief 关于信鸽推送SDK接口协议的对象
  344. */
  345. @property (weak, nonatomic, nullable, readonly) id<XGPushDelegate> delegate;
  346. /**
  347. @brief 信鸽推送管理对象,管理推送的配置选项,例如,注册推送的样式
  348. */
  349. @property (nullable, strong, nonatomic) XGNotificationConfigure *notificationConfigure;
  350. /**
  351. @brief 这个开关表明是否打印信鸽SDK的日志信息
  352. */
  353. @property (assign, getter=isEnableDebug) BOOL enableDebug;
  354. /**
  355. @brief 返回信鸽推送服务的状态
  356. */
  357. @property (assign, readonly) BOOL xgNotificationStatus __deprecated_msg("XG SDK 3.3+, instead, you can use deviceTokenDidRegisteredXGService property");
  358. /**
  359. @brief 设备在信鸽服务中的是否处于注册状态
  360. */
  361. @property (assign, readonly) BOOL deviceDidRegisteredXG;
  362. /**
  363. @brief 管理应用角标
  364. */
  365. @property (nonatomic) NSInteger xgApplicationBadgeNumber;
  366. /**
  367. @brief 通过使用在信鸽官网注册的应用的信息,启动信鸽推送服务
  368. @param appID 通过前台申请的应用ID
  369. @param appKey 通过前台申请的appKey
  370. @param delegate 回调对象
  371. @note 接口所需参数必须要正确填写,反之信鸽服务将不能正确为应用推送消息
  372. */
  373. - (void)startXGWithAppID:(uint32_t)appID appKey:(nonnull NSString *)appKey delegate:(nullable id<XGPushDelegate>)delegate;
  374. /**
  375. @brief 停止信鸽推送服务
  376. @note 调用此方法将导致当前设备不再接受信鸽服务推送的消息.如果再次需要接收信鸽服务的消息推送,则必须需要再次调用startXG:withAppKey:delegate:方法重启信鸽推送服务
  377. */
  378. - (void)stopXGNotification;
  379. /**
  380. @brief 上报应用收到的推送信息,以便信鸽服务能够统计相关数据,包括但不限于:1.推送消息被点击的次数,2.消息曝光的次数
  381. @param info 应用接收到的推送消息对象的内容
  382. @note 请在实现application delegate 的 application:didFinishLaunchingWithOptions:或者application:didReceiveRemoteNotification:的方法中调用此接口,参数就使用这两个方法中的NSDictionaryl类型的参数即可,从而完成推送消息的数据统计
  383. */
  384. - (void)reportXGNotificationInfo:(nonnull NSDictionary *)info;
  385. /**
  386. @brief 上报地理位置信息
  387. @param latitude 纬度
  388. @param longitude 经度
  389. */
  390. - (void)reportLocationWithLatitude:(double)latitude longitude:(double)longitude;
  391. /**
  392. @brief 上报当前App角标数到信鸽服务器
  393. @param badgeNumber 应用的角标数
  394. @note 此接口是为了实现角标+1的功能,服务器会在这个数值基础上进行角标数新增的操作,调用成功之后,会覆盖之前值
  395. */
  396. - (void)setBadge:(NSInteger)badgeNumber;
  397. /**
  398. @brief 上报推送消息的用户行为
  399. @param identifier 用户行为标识
  400. @note 此接口即统计推送消息中开发者预先设置或者是系统预置的行为标识,可以了解到用户是如何处理推送消息的,又统计消息的点击次数
  401. */
  402. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  403. - (void)reportXGNotificationResponse:(nullable UNNotificationResponse *)response __IOS_AVAILABLE(10.0);
  404. #endif
  405. /**
  406. @brief 查询设备通知权限是否被用户允许
  407. @param handler 查询结果的返回方法
  408. @note iOS 10 or later 回调是异步地执行
  409. */
  410. - (void)deviceNotificationIsAllowed:(nonnull void (^)(BOOL isAllowed))handler;
  411. /**
  412. @brief 查看SDK的版本
  413. @return sdk版本号
  414. */
  415. - (nonnull NSString *)sdkVersion;
  416. @end