Plcrashreporter是一个可靠的开源库,可在iOS,MACOS和TVOS上使用一个内部的实时崩溃报告框架。该库检测到崩溃并生成报告,以帮助您调查和对应用程序,系统,过程,线程等以及堆栈痕迹的信息进行故障排除。
使用plcrashreporter的最简单方法是使用AppCenter。但是,如果您想直接使用plcrashreporter,请在发行页面上获取最新版本。
崩溃报告是作为原始图编码的消息输出的,并且可以使用CrashReporter库或任何Google协议缓冲区解码器进行解码。
除了上图内的解码支持外,您还可以使用随附的plcrashutil二进制文件将崩溃报告转换为苹果的标准iPhone文本格式:
plcrashutil convert -- format = iphone example_report . plcrash您可以使用atos命令行工具来象征输出。有关此工具的更多信息,请参见在崩溃报告中添加可识别的符号名称。未来的库版本可能包括内置可重复使用的格式器,用于直接从手机输出替代格式。
可以通过Cocoapods,Carthage,Swift Package Manager或手动将二进制文件添加到您的项目中,可以将Plcrashreporter添加到您的应用中。
Podfile : pod 'PLCrashReporter'pod install以安装您的新定义的POD并打开项目的.xcworkspace 。Cartfile : github "microsoft/plcrashreporter"carthage update --use-xcframeworks获取依赖关系。Frameworks, Libraries and Embedded Content部分中。对于iOS和TVO,将Embed Do not embed 。对于MacOS,将Embed到Embed and Sign 。注意:迦太基集成不会在Xcode 12中正确构建依赖关系,并使用标志“ - 不使用二元组”或特定分支。要使它起作用,请参阅此指令。
注意: plcrashreporter Xcframework包含用于iOS和TVOS的静态二进制文件,以及用于MacOS的动态二进制文件。在将框架添加到项目中时,请确保在
Frameworks, Libraries and Embedded Content部分中Embed嵌入,Do not embediOS和TVOS,并Embed and Sign。PLCrashReporter-Static-{version}.zip是一个例外 - 它包含所有平台的静态框架。
以下示例显示了一种方法来初始化崩溃记者的方法。请注意,启用过程中的崩溃报告将与任何附带的辩论者冲突,因此请确保在崩溃应用程序时不会附加调试器。
@import CrashReporter;
...
// Uncomment and implement isDebuggerAttached to safely run this code with a debugger.
// See: https://github.com/microsoft/plcrashreporter/blob/2dd862ce049e6f43feb355308dfc710f3af54c4d/Source/Crash%20Demo/main.m#L96
// if (![self isDebuggerAttached]) {
// It is strongly recommended that local symbolication only be enabled for non-release builds.
// Use PLCrashReporterSymbolicationStrategyNone for release versions.
PLCrashReporterConfig *config = [[PLCrashReporterConfig alloc ] initWithSignalHandlerType: PLCrashReporterSignalHandlerTypeMach
symbolicationStrategy: PLCrashReporterSymbolicationStrategyAll];
PLCrashReporter *crashReporter = [[PLCrashReporter alloc ] initWithConfiguration: config];
// Enable the Crash Reporter.
NSError *error;
if (![crashReporter enableCrashReporterAndReturnError: &error]) {
NSLog ( @" Warning: Could not enable crash reporter: %@ " , error);
}
// }检查收集的崩溃报告可以通过以下方式完成:
if ([crashReporter hasPendingCrashReport ]) {
NSError *error;
// Try loading the crash report.
NSData *data = [crashReporter loadPendingCrashReportDataAndReturnError: &error];
if (data == nil ) {
NSLog ( @" Failed to load crash report data: %@ " , error);
return ;
}
// Retrieving crash reporter data.
PLCrashReport *report = [[PLCrashReport alloc ] initWithData: data error: &error];
if (report == nil ) {
NSLog ( @" Failed to parse crash report: %@ " , error);
return ;
}
// We could send the report from here, but we'll just print out some debugging info instead.
NSString *text = [PLCrashReportTextFormatter stringValueForCrashReport: report withTextFormat: PLCrashReportTextFormatiOS];
NSLog ( @" %@ " , text);
// Purge the report.
[crashReporter purgePendingCrashReport ];
}import CrashReporter
...
// Uncomment and implement isDebuggerAttached to safely run this code with a debugger.
// See: https://github.com/microsoft/plcrashreporter/blob/2dd862ce049e6f43feb355308dfc710f3af54c4d/Source/Crash%20Demo/main.m#L96
// if (!isDebuggerAttached()) {
// It is strongly recommended that local symbolication only be enabled for non-release builds.
// Use [] for release versions.
let config = PLCrashReporterConfig ( signalHandlerType : . mach , symbolicationStrategy : . all )
guard let crashReporter = PLCrashReporter ( configuration : config ) else {
print ( " Could not create an instance of PLCrashReporter " )
return
}
// Enable the Crash Reporter.
do {
try crashReporter . enableAndReturnError ( )
} catch let error {
print ( " Warning: Could not enable crash reporter: ( error ) " )
}
// }检查收集的崩溃报告可以通过以下方式完成:
// Try loading the crash report.
if crashReporter . hasPendingCrashReport ( ) {
do {
let data = try crashReporter . loadPendingCrashReportDataAndReturnError ( )
// Retrieving crash reporter data.
let report = try PLCrashReport ( data : data )
// We could send the report from here, but we'll just print out some debugging info instead.
if let text = PLCrashReportTextFormatter . stringValue ( for : report , with : PLCrashReportTextFormatiOS ) {
print ( text )
} else {
print ( " CrashReporter: can't convert report to text " )
}
} catch let error {
print ( " CrashReporter failed to load and parse with error: ( error ) " )
}
}
// Purge the report.
crashReporter . purgePendingCrashReport ( ) 此外,下一个可选工具用于构建其他资源:
protobuf-c将协议缓冲器.proto文件转换为C描述符代码。有关更多信息,请参见官方的Protobuf-C-C存储库或使用自制的安装。为您的终端打开一个新窗口。
转到Plcrashreporter的根文件夹并运行
xcodebuild -configuration Release -target ' CrashReporter '为所有平台创建二进制文件。
更新protobuf-c依赖性:
protobuf-ch和protobuf-cc文件。Dependencies/protobuf-c中的现有文件。./Dependencies/protobuf-c/generate-pb-c.sh我们期待您通过拉动请求的贡献。
为了为Plcrashreporter做出贡献,您需要上面提到的工具来为所有架构和protobuf-c构建Plcrashreporter,以将协议缓冲器.proto文件转换为C描述符代码。
该项目采用了Microsoft开源的行为代码。有关更多信息,请参见《行为守则常见问题守则》或与其他问题或评论联系[email protected]。