BPush.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //
  2. // BPush.h
  3. // Version: 1.4.5
  4. // 百度云推送iOS版本头文件 //
  5. //
  6. #import <Foundation/Foundation.h>
  7. #import <UIKit/UIKit.h>
  8. extern NSString *const BPushRequestErrorCodeKey;
  9. extern NSString *const BPushRequestErrorMsgKey;
  10. extern NSString *const BPushRequestRequestIdKey;
  11. extern NSString *const BPushRequestAppIdKey;
  12. extern NSString *const BPushRequestUserIdKey;
  13. extern NSString *const BPushRequestChannelIdKey;
  14. extern NSString *const BPushRequestResponseParamsKey; // 服务端返回的原始值,其内容和以上的部分值可能有重合
  15. /**
  16. * @brief 回调方法名字
  17. *
  18. */
  19. extern NSString *const BPushRequestMethodBind;
  20. extern NSString *const BPushRequestMethodUnbind;
  21. extern NSString *const BPushRequestMethodSetTag;
  22. extern NSString *const BPushRequestMethodDelTag;
  23. extern NSString *const BPushRequestMethodListTag;
  24. /**
  25. * @brief 当前推送的环境
  26. */
  27. typedef NS_ENUM(NSInteger, BPushMode){
  28. BPushModeDevelopment, // 开发测试环境
  29. BPushModeProduction, // AppStore 上线环境 AdHoc 内部测试用的生产环境
  30. };
  31. /**
  32. * @brief BPushCallBack
  33. *
  34. * @discussion 用来设定异步调用的回调
  35. */
  36. typedef void (^BPushCallBack)(id result, NSError *error);
  37. @interface BPush : NSObject
  38. /**
  39. * @brief 注册百度云推送 SDK
  40. * @param
  41. * launchOptions - App 启动时系统提供的参数,表明了 App 是通过什么方式启动的 apiKey - 通过apikey注册百度推送, mode - 当前推送的环境, isdebug - 是否是debug模式。
  42. * iOS 8 新参数
  43. * @param rightAction - 快捷回复通知的第一个按钮名字默认为打开应用
  44. * @param leftAction - 第二个按钮名字默认会关闭应用 iOS 9 快捷回复需要先设置此参数
  45. * @param category 自定义参数 一组动作的唯一标识 需要与服务端aps的category字段匹配才能展现通知样式 iOS 9 快捷回复需要先设置此参数
  46. * IOS 9 新参数
  47. * @param behaviorTextInput 是否启用 iOS 9 快捷回复
  48. */
  49. + (void)registerChannel:(NSDictionary *)launchOptions apiKey:(NSString *)apikey pushMode:(BPushMode)mode withFirstAction:(NSString *)rightAction withSecondAction:(NSString *)leftAction withCategory:(NSString *)category useBehaviorTextInput:(BOOL)behaviorTextInput isDebug:(BOOL)isdebug;
  50. /**
  51. * @brief 向云推送注册 device token,只有在注册deviceToken后才可以绑定
  52. * @param
  53. * deviceToken - 通过 AppDelegate 中的 didRegisterForRemoteNotificationsWithDeviceToken 回调获取
  54. * @return
  55. * none
  56. */
  57. + (void)registerDeviceToken:(NSData *)deviceToken;
  58. /**
  59. * 设置access token. 在bindChannel之前调用,如果access token改变后,必须重新设置并且重新bindChannel
  60. * @param
  61. * token - Access Token
  62. * @return
  63. * none
  64. */
  65. + (void)setAccessToken:(NSString *)token;
  66. /**
  67. * 设置 Bduss
  68. * @param
  69. * bduss - 百度账号体系相关 Bduss
  70. * @return
  71. * none
  72. */
  73. + (void)setBduss:(NSString *)bduss forApp:(NSString *)appid;
  74. /**
  75. * 关闭 lbs
  76. * @param
  77. * - 关闭lbs推送模式,默认是开启的,用户可以选择关闭 需要在调用绑定接口前调用。
  78. * @return
  79. * none
  80. */
  81. + (void)disableLbs;
  82. /**
  83. * @brief 绑定channel.将会在回调中看获得channnelid appid userid 等。
  84. * @param
  85. * none
  86. * @return
  87. * none
  88. */
  89. + (void)bindChannelWithCompleteHandler:(BPushCallBack)handler;
  90. /**
  91. * @brief解除对 channel 的绑定。
  92. * @param
  93. * none
  94. * @return
  95. * none
  96. */
  97. + (void)unbindChannelWithCompleteHandler:(BPushCallBack)handler;
  98. /**
  99. * @brief设置tag。
  100. * @param
  101. * tag - 需要设置的tag
  102. * @return
  103. * none
  104. */
  105. + (void)setTag:(NSString *)tag withCompleteHandler:(BPushCallBack)handler;
  106. /**
  107. * @brief设置多个tag。
  108. * @param
  109. * tags - 需要设置的tag数组
  110. * @return
  111. * none
  112. */
  113. + (void)setTags:(NSArray *)tags withCompleteHandler:(BPushCallBack)handler;
  114. /**
  115. * @brief删除tag。
  116. * @param
  117. * tag - 需要删除的tag
  118. * @return
  119. * none
  120. */
  121. + (void)delTag:(NSString *)tag withCompleteHandler:(BPushCallBack)handler;
  122. /**
  123. * @brief删除多个tag。
  124. * @param
  125. * tags - 需要删除的tag数组
  126. * @return
  127. * none
  128. */
  129. + (void)delTags:(NSArray *)tags withCompleteHandler:(BPushCallBack)handler;
  130. /**
  131. * @brief获取当前设备应用的tag列表。
  132. * @param
  133. * none
  134. * @return
  135. * none
  136. */
  137. + (void)listTagsWithCompleteHandler:(BPushCallBack)handler;
  138. /**
  139. * @brief 在didReceiveRemoteNotification中调用,用于推送反馈
  140. * @param
  141. * userInfo
  142. * @return
  143. * none
  144. */
  145. + (void)handleNotification:(NSDictionary *)userInfo;
  146. /**
  147. * @brief获取应用ID,Channel ID,User ID。如果应用没有绑定,那么返回空
  148. * @param
  149. * none
  150. * @return
  151. * appid/channelid/userid
  152. */
  153. + (NSString *)getChannelId;
  154. + (NSString *)getUserId;
  155. + (NSString *)getAppId;
  156. /**
  157. * 本地推送,最多支持64个
  158. * @param fireDate 本地推送触发的时间
  159. * @param alertBody 本地推送需要显示的内容
  160. * @param badge 角标的数字。如果不需要改变角标传-1
  161. * @param alertAction 弹框的按钮显示的内容(IOS 8默认为"打开",其他默认为"启动")
  162. * @param userInfo 自定义参数,可以用来标识推送和增加附加信息
  163. * @param soundName 自定义通知声音,设置为nil为默认声音
  164. * IOS8新参数
  165. * @param rightAction - 快捷回复通知的第一个按钮名字默认为打开应用
  166. * @param leftAction - 第二个按钮名字默认会关闭应用 iOS 9 快捷回复需要先设置此参数
  167. * @param region 自定义参数
  168. * @param regionTriggersOnce 自定义参数 到达某一区域时,是否触发本地通知
  169. * @param category 自定义参数 一组动作的唯一标示 默认为nil iOS 9 快捷回复需要先设置此参数
  170. * IOS 9 新参数
  171. * @param behaviorTextInput 是否启用 iOS 9 快捷回复
  172. */
  173. + (void)localNotification:(NSDate *)date alertBody:(NSString *)body badge:(int)bage withFirstAction:(NSString *)rightAction withSecondAction:(NSString *)leftAction userInfo:(NSDictionary *)userInfo soundName:(NSString *)soundName region:(CLRegion *)region regionTriggersOnce:(BOOL)regionTriggersOnce category:(NSString *)category useBehaviorTextInput:(BOOL)behaviorTextInput;
  174. /**
  175. * 本地推送在前台推送。默认App在前台运行时不会进行弹窗,在程序接收通知调用此接口可实现指定的推送弹窗。
  176. * @param notification 本地推送对象
  177. * @param notificationKey 需要前台显示的本地推送通知的标示符
  178. */
  179. + (void)showLocalNotificationAtFront:(UILocalNotification *)notification identifierKey:(NSString *)notificationKey;
  180. /**
  181. * 删除本地推送
  182. * @param notificationKey 本地推送标示符
  183. * @param localNotification 本地推送对象
  184. */
  185. + (void)deleteLocalNotificationWithIdentifierKey:(NSString *)notificationKey;
  186. + (void)deleteLocalNotification:(UILocalNotification *)localNotification;
  187. /**
  188. * 获取指定通知
  189. * @param notificationKey 本地推送标示符
  190. * @return 本地推送对象数组,[array count]为0时表示没找到
  191. */
  192. + (NSArray *)findLocalNotificationWithIdentifier:(NSString *)notificationKey;
  193. /**
  194. * 清除所有本地推送对象
  195. */
  196. + (void)clearAllLocalNotifications;
  197. @end