IMSDKBugly.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. //
  2. // IMSDKBugly.h
  3. //
  4. // Version: 1.5.1.11
  5. //
  6. // Created by mqq on 14/12/4.
  7. // Copyright (c) 2015年 tencent.com. All rights reserved.
  8. //
  9. #import <Foundation/Foundation.h>
  10. #pragma mark -
  11. #pragma mark - IMSDKBuglyDelegate
  12. @protocol IMSDKBuglyDelegate <NSObject>
  13. @optional
  14. /**
  15. * @brief Bugly 捕获崩溃后的回调
  16. *
  17. * @param exception Bugly 捕获到的崩溃信息
  18. * @return 自定义附件文本 (最大长度10kb)
  19. */
  20. - (nullable NSString *)attachmentWithSdkCaughtException:(nonnull NSException *)exception;
  21. @end
  22. #pragma mark -
  23. // Log level for Bugly Logger
  24. typedef NS_ENUM(NSUInteger, IMBLYLogLevel) {
  25. IMBLYLogLevelSilent = 0,
  26. IMBLYLogLevelError = 1 << 0, // 00001
  27. IMBLYLogLevelWarn = 1 << 1, // 00010
  28. IMBLYLogLevelInfo = 1 << 2, // 00100
  29. IMBLYLogLevelDebug = 1 << 3, // 01000
  30. IMBLYLogLevelVerbose = 1 << 4, // 10000
  31. };
  32. #pragma mark -
  33. #pragma mark - IMSDKBuglyConfig
  34. @interface IMSDKBuglyConfig : NSObject
  35. /**
  36. * @brief delegate
  37. */
  38. @property (nonatomic, weak, nullable) id<IMSDKBuglyDelegate> delegate;
  39. /**
  40. * @brief 是否打印SDK调试信息,默认为NO
  41. */
  42. @property (nonatomic, assign) BOOL debug;
  43. /**
  44. * @brief 应用版本是否包含CFBundleShortVersionString字段,默认为YES,版本包含此字段
  45. */
  46. @property (nonatomic, assign) BOOL useDefaultVersionField;
  47. /**
  48. * @brief 应用版本是否包含CFBundleVersion字段,默认为YES,版本包含此字段
  49. */
  50. @property (nonatomic, assign) BOOL useDefaultBuildField;
  51. /**
  52. * @brief 设置应用版本信息,默认版本为CFBundleShortVersionString(CFBundleVersion)
  53. */
  54. @property (nonatomic, copy, nullable) NSString * version ;
  55. /**
  56. * @brief 设置渠道名, 默认Unknown
  57. */
  58. @property (nonatomic, copy, nullable) NSString *channel;
  59. /**
  60. * @brief 设置默认用户标识,默认Unknown
  61. */
  62. @property (nonatomic, copy, nullable) NSString *userIdentifier;
  63. /**
  64. * @brief 设置设备的唯一标识, 默认采用SDK定义的设备唯一标识
  65. */
  66. @property (nonatomic, copy, nullable) NSString *deviceIdentifier;
  67. /**
  68. * @brief 设置应用的标识,默认读取.plist对应字段
  69. */
  70. @property (nonatomic, copy, nullable) NSString *bundleIdentifier;
  71. /**
  72. * @brief 是否开启卡顿监控上报,默认NO,开启卡顿场景监控上报
  73. */
  74. @property (nonatomic, assign) BOOL enableBlockMonitor;
  75. /**
  76. * @brief 设置卡顿监控的RunLoop超时判断阀值,默认值 3 sec.
  77. */
  78. @property (nonatomic, assign) NSUInteger blockMonitorJudgementLoopTimeout;
  79. /**
  80. * @brief 设置是否启用进程内符号化,默认为YES,开启进程内符号化,请修改Xcode配置Strip Style为Debugging Symbols
  81. */
  82. @property (nonatomic, assign) BOOL enableSymbolicateInProcess;
  83. /**
  84. * @brief 设置是否启用 App Transport Security,默认为YES
  85. */
  86. @property (nonatomic, assign) BOOL enableATS;
  87. /**
  88. * @brief 设置是否启用非正常退出事件上报,默认为NO
  89. */
  90. @property (nonatomic, assign) BOOL enableUnexpectedTerminatingDetection;
  91. /**
  92. * 页面信息记录开关,默认开启
  93. */
  94. @property (nonatomic) BOOL enableViewControllerTracking;
  95. /**
  96. * 控制台日志上报开关,默认开启
  97. */
  98. @property (nonatomic, assign) BOOL enableConsoleLogReport;
  99. /**
  100. * @brief 控制自定义日志的上报,默认值为IMBLYLogLevelInfo,即自动上报Info级别以上的日志。如设置为IMBLYLogLevelWarn,则会在崩溃发生时,上报IMBLYLogLevelError、MBLYLogLevelWarn的日志
  101. */
  102. @property (nonatomic, assign) IMBLYLogLevel reportLogLevel;
  103. /**
  104. * @brief 默认配置实例
  105. *
  106. * @return
  107. */
  108. + (nonnull instancetype)defaultConfig;
  109. @end
  110. #pragma mark - IMSDKBugly
  111. @interface IMSDKBugly : NSObject
  112. /**
  113. * @brief 初始化日志模块
  114. *
  115. * @param level 设置默认日志级别,默认BLYLogLevelInfo
  116. *
  117. * @param printConsole 是否打印到控制台,默认NO
  118. */
  119. + (void)initLogger:(IMBLYLogLevel) level consolePrint:(BOOL) printConsole DEPRECATED_MSG_ATTRIBUTE("DEPRECATED in 1.5.1 or higher version");
  120. /**
  121. * @brief 获取默认的日志级别
  122. *
  123. * @return BLYLogLevel
  124. */
  125. + (IMBLYLogLevel)logLevel;
  126. /**
  127. * @brief 打印BLYLogLevelInfo日志
  128. *
  129. * @param format 日志内容
  130. */
  131. + (void)log:(nonnull NSString *)format, ... DEPRECATED_MSG_ATTRIBUTE("DEPRECATED in 1.5.1 or higher version");
  132. /**
  133. * @brief 打印日志
  134. *
  135. * @param level 日志级别
  136. * @param fmt 日志内容
  137. */
  138. + (void)level:(IMBLYLogLevel) level logs:(nonnull NSString *)message;
  139. /**
  140. * @brief 打印日志
  141. *
  142. * @param level 日志级别
  143. * @param fmt 日志内容
  144. */
  145. + (void)level:(IMBLYLogLevel) level log:(nonnull NSString *)format, ... DEPRECATED_MSG_ATTRIBUTE("DEPRECATED in 1.5.1 or higher version");
  146. /**
  147. * @brief 打印日志
  148. *
  149. * @param level 日志级别
  150. * @param tag 日志模块分类
  151. * @param format 日志内容
  152. */
  153. + (void)level:(IMBLYLogLevel)level tag:(nonnull NSString *) tag log:(nonnull NSString *)format, ... DEPRECATED_MSG_ATTRIBUTE("DEPRECATED in 1.5.1 or higher version");
  154. /**
  155. * @brief 初始化IMSDKBugly崩溃上报,在application:didFinishLaunchingWithOptions:方法中调用
  156. *
  157. * @param appId 应用的唯一标识,在Bugly网站注册应用后获取
  158. */
  159. + (void)startWithAppId:(nonnull NSString *)appId;
  160. /**
  161. * @brief 初始化IMSDKBugly,并设置默认配置,默认配置内容可以查看IMSDKBuglyConfig了解
  162. *
  163. * @param appId 应用的唯一标识,在Bugly网站注册应用后获取
  164. * @param defaultConfig 默认配置
  165. */
  166. + (void)startWithAppId:(nonnull NSString *)appId
  167. config:(nullable IMSDKBuglyConfig *)config;
  168. /**
  169. * @brief 初始化IMSDKBugly,并设置AppGroups标识(如果需要支持App Extension异常上报,请调用此接口初始化)
  170. *
  171. * @param appId 应用的唯一标识,在Bugly网站注册应用后获取
  172. * @param defaultConfig 默认配置
  173. * @param appGroupIdentifier AppGroups 标识
  174. */
  175. + (void)startWithAppId:(nonnull NSString *)appId
  176. config:(nullable IMSDKBuglyConfig *)config
  177. applicationGroupIdentifier:(nonnull NSString *)appGroupIdentifier;
  178. /**
  179. * @brief 设置用户唯一标识,在初始化方法之后调用
  180. *
  181. * @param userId 用户唯一标识
  182. */
  183. + (void)setUserIdentifier:(nonnull NSString *)userId;
  184. /**
  185. * @brief 设置场景标签, 如支付、后台等
  186. *
  187. * @param tagid 自定义的场景标签Id, 需先在Bugly平台页面进行配置
  188. */
  189. + (void)setTagId:(NSUInteger)tagid;
  190. /**
  191. * @brief 设置自定义数据,最多保存20条记录
  192. *
  193. * @param value
  194. * @param key
  195. */
  196. + (void)setSceneValue:(nonnull NSString *)value
  197. forKey:(nonnull NSString *)key;
  198. /**
  199. * @brief 获取指定key自定义数据
  200. *
  201. * @param key
  202. */
  203. + (nullable NSString *)sceneValueForKey:(nonnull NSString *)key;
  204. /**
  205. * @brief 获取所有自定义数据,Key-Value为NSString
  206. */
  207. + (nullable NSDictionary<NSString *, NSString *> *)allSceneValues;
  208. /**
  209. * @brief 删除指定key自定义数据
  210. *
  211. * @param key
  212. */
  213. + (void)removeSceneValueForKey:(nonnull NSString *)key;
  214. /**
  215. * @brief 删除所有自定义数据
  216. */
  217. + (void)removeAllSceneValues;
  218. /**
  219. * @brief 上报NSException
  220. *
  221. * @param exception 自定义异常
  222. * @param reason 异常原因
  223. * @param dict 附带数据,Key-Value为NSString
  224. */
  225. + (void)reportException:(nonnull NSException *)exception
  226. reason:(nullable NSString *)reason
  227. extraInfo:(nullable NSDictionary *)dict;
  228. /**
  229. * @brief 上报NSError
  230. *
  231. * @param error 自定义Error
  232. * @param reason 错误原因
  233. * @param dict 附带数据
  234. */
  235. + (void)reportError:(nonnull NSError *)error
  236. reason:(nullable NSString *)reason
  237. extraInfo:(nullable NSDictionary *)dict;
  238. /**
  239. * @brief 上报自定义异常信息
  240. *
  241. * @param category 自定义异常类型, C# = 4、JS = 5、Lua = 6
  242. * @param name 异常名称
  243. * @param reason 异常原因
  244. * @param stack 异常堆栈
  245. * @param dict 附加数据,Key-Value为NSString
  246. * @param terminate 是否中止应用
  247. */
  248. + (void)reportExceptionCategory:(NSUInteger)category
  249. name:(nonnull NSString *)name
  250. reason:(nullable NSString *)reason
  251. stackTrace:(nullable NSString *)stack
  252. extraInfo:(nullable NSDictionary *)dict
  253. terminateApp:(BOOL)terminate;
  254. /**
  255. * 获取SDK的版本信息
  256. *
  257. */
  258. + (nonnull NSString *)sdkVersion;
  259. /**
  260. * 设置SDK的唯一标识及SDK的版本信息
  261. *
  262. * @param componentId 组件模块唯一标识
  263. * @param version 版本信息
  264. */
  265. + (void)setComponentIdentifier:(nonnull NSString *) componentId version:(nonnull NSString *)version;
  266. /**
  267. * 设置附加信息
  268. *
  269. */
  270. + (void)setSdkConfig:(nonnull NSString *) value forKey:(nonnull NSString *) key;
  271. @end