Crasheye.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /**
  2. * Unity Plugins Version 2.2.10
  3. *
  4. * android version 2.2.9
  5. * iOS version 2.7.3
  6. * window version 1.0.0
  7. */
  8. using System.Text;
  9. using UnityEngine;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System;
  13. using System.IO;
  14. using System.Runtime.InteropServices;
  15. using System.Security.Cryptography;
  16. using System.Text.RegularExpressions;
  17. #if UNITY_ANDROID || UNITY_IPHONE || UNITY_IOS
  18. using com.xsj.Crasheye.U3D;
  19. #endif
  20. #if UNITY_ANDROID
  21. using com.xsj.Crasheye.U3D.Android;
  22. #endif
  23. #if UNITY_IPHONE || UNITY_IOS
  24. using com.xsj.Crasheye.U3D.IOS;
  25. #endif
  26. public class Crasheye : MonoBehaviour
  27. {
  28. public delegate void FnOnCrashCallback(bool bCaptureSucceed, string cpszCrashReportFile);
  29. public string YourAppKeyForAndroid = "YourAppKeyForAndroid";
  30. public string YourChannelIdForAndroid = "YourChannelIdForAndroid";
  31. public string YourAppKeyForIOS = "YourAppKeyForIOS";
  32. public string YourChannelIdForIOS = "YourChannelIdForIOS";
  33. public string YourAppKeyForPC = "YourAppKeyForPC";
  34. public string YourChannelIdForPC = "YourChannelIdForPC";
  35. #if UNITY_ANDROID || UNITY_IPHONE || UNITY_IOS
  36. public static CrasheyeLib crasheyeLib = null;
  37. #endif
  38. #if UNITY_ANDROID || UNITY_IPHONE || UNITY_IOS || UNITY_STANDALONE_WIN
  39. private static string YourChannelId = "NA";
  40. #endif
  41. public static void AddCustomLog(string collectFile)
  42. {
  43. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  44. DumpForPC.AddCustomLog(collectFile);
  45. #endif
  46. }
  47. public static void AddCustomLogDirectory(string CollectLogDirectory)
  48. {
  49. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  50. DumpForPC.AddCustomLogDirectory(CollectLogDirectory);
  51. #endif
  52. }
  53. void Awake()
  54. {
  55. DontDestroyOnLoad(gameObject);
  56. if (Application.platform == RuntimePlatform.Android)
  57. {
  58. #if UNITY_ANDROID
  59. SetChannelID(YourChannelIdForAndroid);
  60. StartInitCrasheye(YourAppKeyForAndroid);
  61. CrashSightAgent.ConfigDebugMode(false);
  62. // 设置上报的目标域名,请根据项目需求进行填写。(必填)
  63. CrashSightAgent.ConfigCrashServerUrl("https://android.crashsight.qq.com/pb/async");
  64. CrashSightAgent.ConfigCrashReporter(1);
  65. // 设置上报所指向的APP ID, 并进行初始化。APPID可以在管理端更多->产品设置->产品信息中找到。
  66. CrashSightAgent.InitWithAppId("3115889696");
  67. #endif
  68. }
  69. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  70. {
  71. #if UNITY_IPHONE || UNITY_IOS
  72. SetChannelID(YourChannelIdForIOS);
  73. StartInitCrasheye(YourAppKeyForIOS);
  74. #endif
  75. }
  76. else if (Application.platform == RuntimePlatform.WindowsPlayer)
  77. {
  78. #if UNITY_STANDALONE_WIN
  79. SetChannelID(YourAppKeyForPC);
  80. StartInitCrasheye(YourAppKeyForPC);
  81. #endif
  82. }
  83. }
  84. /// <summary>
  85. /// SetURL
  86. /// </summary>
  87. /// <param name="SetUrl"></param>
  88. public static void SetURL(string url)
  89. {
  90. if (Application.platform == RuntimePlatform.Android)
  91. {
  92. #if UNITY_ANDROID
  93. CrasheyeForAndroid.SetURL(url);
  94. #endif
  95. }
  96. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  97. {
  98. #if UNITY_IPHONE || UNITY_IOS
  99. CrasheyeForIOS.SetURL(url);
  100. #endif
  101. }
  102. else if (Application.platform == RuntimePlatform.WindowsPlayer)
  103. {
  104. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  105. DumpForPC.SetURL(url);
  106. #endif
  107. }
  108. }
  109. /// <summary>
  110. /// 设置Dump是否强制上报(忽略玩家在DumpReport界面上的选择)
  111. ///
  112. /// </summary>
  113. /// <param name="isForceUpload"> isForceUpload 是否设置Dump强制上报 </param>
  114. public static void SetForceUpload(bool isForceUpload)
  115. {
  116. Debug.Log("SetForceUpload");
  117. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  118. DumpForPC.SetForceUpload(isForceUpload);
  119. #endif
  120. }
  121. /// <summary>
  122. /// 启动Crasheye
  123. /// </summary>
  124. /// <param name="Your_AppKey"></param>
  125. public static void StartInitCrasheye(string Your_AppKey)
  126. {
  127. RegisterLogCallback();
  128. if (Application.platform == RuntimePlatform.Android)
  129. {
  130. #if UNITY_ANDROID
  131. CrasheyeForAndroid.Init(Your_AppKey, YourChannelId);
  132. #endif
  133. }
  134. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  135. {
  136. #if UNITY_IPHONE || UNITY_IOS
  137. CrasheyeForIOS.Init(Your_AppKey, YourChannelId);
  138. #endif
  139. }
  140. else if (Application.platform == RuntimePlatform.WindowsPlayer)
  141. {
  142. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  143. DumpForPC.Init(Your_AppKey, YourChannelId);
  144. #endif
  145. }
  146. //bool result = Crasheye.PushLogTrace("Crasheye Demo Push Log");
  147. //Debug.Log("PushLogTrace:" + result);
  148. }
  149. /// <summary>
  150. /// 注册脚本捕获
  151. /// </summary>
  152. public static void RegisterLogCallback()
  153. {
  154. if (Application.platform == RuntimePlatform.Android)
  155. {
  156. #if UNITY_ANDROID
  157. crasheyeLib = new LibForAndroid();
  158. CrasheyeForAndroid.setInternalExtraData();
  159. #endif
  160. }
  161. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  162. {
  163. #if UNITY_IPHONE || UNITY_IOS
  164. crasheyeLib = new LibForiOS();
  165. #endif
  166. }
  167. else if (Application.platform == RuntimePlatform.WindowsPlayer)
  168. {
  169. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  170. Debug.Log("RegisterLogCallback");
  171. AppDomain.CurrentDomain.UnhandledException += DumpForPC.OnHandleUnresolvedException;
  172. SetRegisterLogFunction(DumpForPC.OnHandleLogCallback);
  173. Application.logMessageReceived += RegisterLogFunction;
  174. #endif
  175. }
  176. #if UNITY_ANDROID || UNITY_IPHONE || UNITY_IOS
  177. if (crasheyeLib == null)
  178. {
  179. return;
  180. }
  181. System.AppDomain.CurrentDomain.UnhandledException +=
  182. new System.UnhandledExceptionEventHandler(crasheyeLib.OnHandleUnresolvedException);
  183. SetRegisterLogFunction(crasheyeLib.OnHandleLogCallback);
  184. #if UNITY_5
  185. Application.logMessageReceived += RegisterLogFunction;
  186. #else
  187. Application.RegisterLogCallback(RegisterLogFunction);
  188. #endif
  189. #endif
  190. }
  191. private static void RegisterLogFunction(string logString, string stackTrace, LogType type)
  192. {
  193. #if (UNITY_IPHONE || UNITY_IOS) && !UNITY_EDITOR
  194. if (Application.platform == RuntimePlatform.IPhonePlayer)
  195. {
  196. CrasheyeForIOS.SaveLogger(logString);
  197. }
  198. if (CrasheyeForIOS.GetLoggingLines() > 0 &&
  199. Application.platform == RuntimePlatform.IPhonePlayer &&
  200. (type == LogType.Assert || type == LogType.Exception)
  201. )
  202. {
  203. CrasheyeForIOS.addLog(CrasheyeForIOS.GetLogger());
  204. }
  205. #endif
  206. if (m_RegisterLog != null)
  207. {
  208. m_RegisterLog(logString, stackTrace, type);
  209. }
  210. #if (UNITY_IPHONE || UNITY_IOS) && !UNITY_EDITOR
  211. if (CrasheyeForIOS.GetLoggingLines() > 0 &&
  212. Application.platform == RuntimePlatform.IPhonePlayer &&
  213. (type == LogType.Assert || type == LogType.Exception)
  214. )
  215. {
  216. CrasheyeForIOS.removeLog();
  217. }
  218. #endif
  219. }
  220. public delegate void RegisterLog(string logString, string stackTrace, LogType type);
  221. private static RegisterLog m_RegisterLog = null;
  222. /// <summary>
  223. /// 设置用户的脚本回调的函数
  224. /// </summary>
  225. /// <param name="registerLogCBFun"></param>
  226. public static void SetRegisterLogFunction(RegisterLog registerLogCBFun)
  227. {
  228. Debug.Log("SetRegisterLogFunction");
  229. m_RegisterLog += registerLogCBFun;
  230. }
  231. /// <summary>
  232. /// 发送脚本异常
  233. /// </summary>
  234. /// <param name="ex">Excepiton Info</param>
  235. public static void SendScriptException(Exception ex)
  236. {
  237. if (Application.platform == RuntimePlatform.Android)
  238. {
  239. #if UNITY_ANDROID
  240. crasheyeLib.LibSendScriptException(ex.Message, ex.StackTrace);
  241. #endif
  242. }
  243. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  244. {
  245. #if UNITY_IPHONE || UNITY_IOS
  246. crasheyeLib.LibSendScriptException(ex.Message, ex.StackTrace);
  247. #endif
  248. }
  249. }
  250. /// <summary>
  251. /// 上报脚本异常
  252. /// </summary>
  253. /// <param name="errorTitle">错误的标题</param>
  254. /// <param name="stacktrace">错误堆栈信息</param>
  255. /// <param name="language">语言</param>
  256. public static void SendScriptException(string errorTitle, string stacktrace, string language)
  257. {
  258. if (Application.platform == RuntimePlatform.Android)
  259. {
  260. #if UNITY_ANDROID
  261. crasheyeLib.LibSendScriptException(errorTitle, stacktrace, language);
  262. #endif
  263. }
  264. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  265. {
  266. #if UNITY_IPHONE || UNITY_IOS
  267. crasheyeLib.LibSendScriptException(errorTitle, stacktrace);
  268. #endif
  269. }
  270. else if (Application.platform == RuntimePlatform.WindowsPlayer)
  271. {
  272. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  273. DumpForPC.SendScriptException(errorTitle, stacktrace, language);
  274. #endif
  275. }
  276. }
  277. /// <summary>
  278. /// 设置渠道号
  279. /// </summary>
  280. /// <param name="yourChannelID"></param>
  281. public static void SetChannelID(string yourChannelID)
  282. {
  283. if (String.IsNullOrEmpty(yourChannelID))
  284. {
  285. Debug.LogError("set channel id value is null or empty!");
  286. return;
  287. }
  288. if (yourChannelID.Equals("YourChannelIdForAndroid") || yourChannelID.Equals("YourChannelIdForIOS"))
  289. {
  290. return;
  291. }
  292. #if UNITY_ANDROID || UNITY_IPHONE || UNITY_IOS || UNITY_STANDALONE_WIN
  293. YourChannelId = yourChannelID;
  294. #endif
  295. }
  296. /// <summary>
  297. /// 设置是否只在wifi下上报报告文件
  298. /// </summary>
  299. /// <param name="enabled"></param>
  300. public static void SetFlushOnlyOverWiFi(bool enabled)
  301. {
  302. if (Application.platform == RuntimePlatform.Android)
  303. {
  304. #if UNITY_ANDROID
  305. CrasheyeForAndroid.SetFlushOnlyOverWiFi(enabled);
  306. #endif
  307. }
  308. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  309. {
  310. #if UNITY_IPHONE || UNITY_IOS
  311. CrasheyeForIOS.SetFlushOnlyOverWiFi(enabled);
  312. #endif
  313. }
  314. }
  315. /// <summary>
  316. /// 设置该版本是否为测试版本
  317. /// </summary>
  318. /// <param name="isBeta">是否为测试版本</param>
  319. public static void SetIsBetaVersion(bool isBeta)
  320. {
  321. if (Application.platform == RuntimePlatform.Android)
  322. {
  323. #if UNITY_ANDROID
  324. CrasheyeForAndroid.SetIsBetaVersion(isBeta);
  325. #endif
  326. }
  327. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  328. {
  329. #if UNITY_IPHONE || UNITY_IOS
  330. CrasheyeForIOS.SetBeta(isBeta);
  331. #endif
  332. }
  333. else if (Application.platform == RuntimePlatform.WindowsPlayer)
  334. {
  335. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  336. DumpForPC.SetBeta();
  337. #endif
  338. }
  339. }
  340. /// <summary>
  341. /// 设置版本号信息
  342. /// </summary>
  343. /// <param name="yourAppVersion">App版本号</param>
  344. public static void SetAppVersion(string yourAppVersion)
  345. {
  346. if (Application.platform == RuntimePlatform.Android)
  347. {
  348. #if UNITY_ANDROID
  349. CrasheyeForAndroid.SetAppVersion(yourAppVersion);
  350. #endif
  351. }
  352. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  353. {
  354. #if UNITY_IPHONE || UNITY_IOS
  355. CrasheyeForIOS.SetAppVersion(yourAppVersion);
  356. #endif
  357. }
  358. else if (Application.platform == RuntimePlatform.WindowsPlayer)
  359. {
  360. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  361. DumpForPC.SetAppVersion(yourAppVersion);
  362. #endif
  363. }
  364. }
  365. /// <summary>
  366. /// 设置用户信息
  367. /// </summary>
  368. /// <param name="setUserIdentifier">用户标识</param>
  369. public static void SetUserIdentifier(string userIdentifier)
  370. {
  371. if (string.IsNullOrEmpty(userIdentifier))
  372. {
  373. return;
  374. }
  375. if (Application.platform == RuntimePlatform.Android)
  376. {
  377. #if UNITY_ANDROID
  378. CrasheyeForAndroid.SetUserIdentifier(userIdentifier);
  379. #endif
  380. }
  381. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  382. {
  383. #if UNITY_IPHONE || UNITY_IOS
  384. CrasheyeForIOS.SetUserIdentifier(userIdentifier);
  385. #endif
  386. }
  387. else if (Application.platform == RuntimePlatform.WindowsPlayer)
  388. {
  389. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  390. DumpForPC.SetUserIdentifier_UTF8(userIdentifier);
  391. #endif
  392. }
  393. }
  394. /// <summary>
  395. /// 如果启动了C#堆栈回溯可能会导致某些机型出现宕机
  396. /// </summary>
  397. public static void EnableCSharpStackTrace()
  398. {
  399. #if UNITY_ANDROID
  400. CrasheyeForAndroid.EnableCSharpStackTrace();
  401. #endif
  402. }
  403. /// <summary>
  404. /// 添加自定义数据
  405. /// </summary>
  406. /// <param name="key">Key.</param>
  407. /// <param name="value">Value.</param>
  408. public static void AddExtraData(string key, string value)
  409. {
  410. if (Application.platform == RuntimePlatform.Android)
  411. {
  412. #if UNITY_ANDROID
  413. CrasheyeForAndroid.AddExtraData(key, value);
  414. #endif
  415. }
  416. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  417. {
  418. #if UNITY_IPHONE || UNITY_IOS
  419. CrasheyeForIOS.AddExtraData(key, value);
  420. #endif
  421. }
  422. else if (Application.platform == RuntimePlatform.WindowsPlayer)
  423. {
  424. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  425. DumpForPC.AddExtraData(key,value);
  426. #endif
  427. }
  428. }
  429. public static void AddExtraDataUTF8(string key, string value)
  430. {
  431. if (Application.platform == RuntimePlatform.Android)
  432. {
  433. #if UNITY_ANDROID
  434. CrasheyeForAndroid.AddExtraData(key, value);
  435. #endif
  436. }
  437. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  438. {
  439. #if UNITY_IPHONE || UNITY_IOS
  440. CrasheyeForIOS.AddExtraData(key, value);
  441. #endif
  442. }
  443. else if (Application.platform == RuntimePlatform.WindowsPlayer)
  444. {
  445. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  446. DumpForPC.AddExtraDataUTF8(key, value);
  447. #endif
  448. }
  449. }
  450. /// <summary>
  451. /// 获取自定义数据
  452. /// </summary>
  453. /// <param name="key">Key</param>
  454. /// <returns></returns>
  455. public static string GetExtraData(string key)
  456. {
  457. string extraData = "";
  458. if (string.IsNullOrEmpty(key))
  459. {
  460. return extraData;
  461. }
  462. if (Application.platform == RuntimePlatform.Android)
  463. {
  464. #if UNITY_ANDROID
  465. extraData = CrasheyeForAndroid.GetExtraData(key);
  466. #endif
  467. }
  468. else
  469. {
  470. #if UNITY_IPHONE || UNITY_IOS
  471. extraData = CrasheyeForIOS.GetExtraData(key);
  472. #endif
  473. }
  474. return extraData;
  475. }
  476. /// <summary>
  477. /// 移除自定义值
  478. /// </summary>
  479. /// <param name="key">Key</param>
  480. public static void RemoveExtraData(string key)
  481. {
  482. if (string.IsNullOrEmpty(key))
  483. {
  484. return;
  485. }
  486. if (Application.platform == RuntimePlatform.Android)
  487. {
  488. #if UNITY_ANDROID
  489. CrasheyeForAndroid.RemoveExtraData(key);
  490. #endif
  491. }
  492. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  493. {
  494. #if UNITY_IPHONE || UNITY_IOS
  495. CrasheyeForIOS.RemoveExtraData(key);
  496. #endif
  497. }
  498. }
  499. /// <summary>
  500. /// 清除自定义数据
  501. /// </summary>
  502. public static void CleanExtraData()
  503. {
  504. if (Application.platform == RuntimePlatform.Android)
  505. {
  506. #if UNITY_ANDROID
  507. CrasheyeForAndroid.CleanExtraData();
  508. #endif
  509. }
  510. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  511. {
  512. #if UNITY_IPHONE || UNITY_IOS
  513. CrasheyeForIOS.ClearExtraData();
  514. #endif
  515. }
  516. }
  517. /// <summary>
  518. /// 设置打点数据接口
  519. /// </summary>
  520. /// <param name="breadcrumb">Breadcrumb.</param>
  521. public static void SetBreadCrumbType(Int32 type)
  522. {
  523. if (Application.platform == RuntimePlatform.Android)
  524. {
  525. #if UNITY_ANDROID
  526. // TODO
  527. #endif
  528. }
  529. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  530. {
  531. #if UNITY_IPHONE || UNITY_IOS
  532. // TODO
  533. #endif
  534. }
  535. else if (Application.platform == RuntimePlatform.WindowsPlayer)
  536. {
  537. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  538. DumpForPC.SetBreadCrumbType(type);
  539. #endif
  540. }
  541. }
  542. /// <summary>
  543. /// 打点数据
  544. /// </summary>
  545. /// <param name="breadcrumb">Breadcrumb.</param>
  546. public static void LeaveBreadcrumb(string breadcrumb)
  547. {
  548. if (string.IsNullOrEmpty(breadcrumb))
  549. {
  550. return;
  551. }
  552. if (Application.platform == RuntimePlatform.Android)
  553. {
  554. #if UNITY_ANDROID
  555. CrasheyeForAndroid.LeaveBreadcrumb(breadcrumb);
  556. #endif
  557. }
  558. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  559. {
  560. #if UNITY_IPHONE || UNITY_IOS
  561. CrasheyeForIOS.LeaveBreadcrumb(breadcrumb);
  562. #endif
  563. }
  564. else if (Application.platform == RuntimePlatform.WindowsPlayer)
  565. {
  566. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  567. DumpForPC.leaveBreadcrumb(breadcrumb);
  568. #endif
  569. }
  570. }
  571. /// <summary>
  572. /// 指定获取应用程序log日志的行数
  573. /// </summary>
  574. /// <param name="lines">需要获取log行数</param>
  575. public static void SetLogging(int lines)
  576. {
  577. if (Application.platform == RuntimePlatform.Android)
  578. {
  579. #if UNITY_ANDROID
  580. CrasheyeForAndroid.SetLogging(lines);
  581. #endif
  582. }
  583. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  584. {
  585. #if UNITY_IPHONE || UNITY_IOS
  586. CrasheyeForIOS.SetLogging(lines);
  587. #endif
  588. }
  589. }
  590. /// <summary>
  591. /// 获取应用程序log日志关键字过滤
  592. /// </summary>
  593. /// <param name="filter">需要过滤关键字</param>
  594. public static void SetLogging(string filter)
  595. {
  596. if (string.IsNullOrEmpty(filter))
  597. {
  598. return;
  599. }
  600. if (Application.platform == RuntimePlatform.Android)
  601. {
  602. #if UNITY_ANDROID
  603. CrasheyeForAndroid.SetLogging(filter);
  604. #endif
  605. }
  606. }
  607. /// <summary>
  608. /// 获取应用程序log日志(过滤条件:关键字过滤+行数)
  609. /// </summary>
  610. /// <param name="lines">需要获取的行数</param>
  611. /// <param name="filter">需要过滤的关键字</param>
  612. public static void SetLogging(int lines, string filter)
  613. {
  614. if (string.IsNullOrEmpty(filter))
  615. {
  616. return;
  617. }
  618. if (Application.platform == RuntimePlatform.Android)
  619. {
  620. #if UNITY_ANDROID
  621. CrasheyeForAndroid.SetLogging(lines, filter);
  622. #endif
  623. }
  624. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  625. {
  626. #if UNITY_IPHONE || UNITY_IOS
  627. CrasheyeForIOS.SetLogging(lines, filter);
  628. #endif
  629. }
  630. }
  631. /// <summary>
  632. /// 获取sdk版本号
  633. /// </summary>
  634. /// <returns></returns>
  635. public static string GetAppVersion()
  636. {
  637. if (Application.platform == RuntimePlatform.Android)
  638. {
  639. #if UNITY_ANDROID
  640. return CrasheyeForAndroid.GetAppVersion();
  641. #endif
  642. }
  643. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  644. {
  645. #if UNITY_IPHONE || UNITY_IOS
  646. return CrasheyeForIOS.GetAppVersion();
  647. #endif
  648. }
  649. return "NA";
  650. }
  651. public static bool SetBackgroundUpload(bool isBackgroundUpload)
  652. {
  653. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  654. return DumpForPC.SetBackgroundUpload(isBackgroundUpload);
  655. #endif
  656. return false;
  657. }
  658. public static bool SetCrashCallback(FnOnCrashCallback pCallback)
  659. {
  660. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  661. return DumpForPC.SetOnMiniDumpCreateCallBack((bCaptureSucceed, cpszCrashReportFile)=>{
  662. string szCrashReportFile = Marshal.PtrToStringUni(cpszCrashReportFile);
  663. pCallback?.Invoke(bCaptureSucceed, szCrashReportFile);
  664. });
  665. #endif
  666. return false;
  667. }
  668. public static bool PushLogTrace(string cpszMessage)
  669. {
  670. #if UNITY_STANDALONE_WIN && !UNITY_EDITOR
  671. return DumpForPC.PushLogTrace(cpszMessage);
  672. #endif
  673. return false;
  674. }
  675. }