Crasheye.cs 20 KB

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