包含单个应用程序崩溃事件的数据,以及提供对所有已收集的崩溃报告的访问。
如果使用适当的设置进行编译,Unity 将在您的应用程序崩溃时尝试收集有用信息,例如位置和线程堆栈跟踪。在下一次应用程序启动时,如果数据收集成功,则所有崩溃信息都可使用此 API 进行访问。
要启用崩溃报告生成,则在 iOS Player Settings 中,将“Script Call Optimization”选项设置为“Fast but no Exceptions”。在 Unity 中构建了您的 Xcode 项目后,打开该项目,然后编辑 trampoline 文件:Classes/CrashReporter.h。将 ENABLE_CUSTOM_CRASH_REPORTER 定义从 0 更改为 1。注意,iOS Player Settings 包含一个具有“Enable CrashReport API”的 Crash Reporting 设置。
注意:此 API 当前仅针对 iOS。
另请参阅:CrashReport.reports。
using UnityEngine;
// This example shows a list of crash reports (if available), // and allows you to output crash data to console, or // delete them. public class Crashes : MonoBehaviour { void OnGUI() { var reports = CrashReport.reports; GUILayout.Label("Crash reports:"); foreach (var r in reports) { GUILayout.BeginHorizontal(); GUILayout.Label("Crash: " + r.time); if (GUILayout.Button("Log")) { Debug.Log(r.text); } if (GUILayout.Button("Remove")) { r.Remove(); } GUILayout.EndHorizontal(); } } }
lastReport | 返回上次崩溃报告,或者如果没有可用报告,则返回 null。 |
reports | 在一个新的数组中返回所有当前可用的报告。 |
Remove | 将报告从可用报告列表中移除。 |
RemoveAll | 将所有报告从可用报告列表中移除。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.