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]。