Plcrashreporterは、iOS、MacOS、TVOで使用するプロセス内のライブクラッシュレポートフレームワークを提供する信頼できるオープンソースライブラリです。ライブラリは、クラッシュを検出してレポートを生成して、アプリケーション、システム、プロセス、スレッドなどの情報とスタックトレースの情報を使用して、調査とトラブルシューティングを支援します。
plcrashreporterを使用する最も簡単な方法は、Appcenterを使用することです。ただし、plcrashreporterを直接使用する場合は、リリースページで最新リリースを入手してください。
クラッシュレポートは、プロトブフエンコードメッセージとして出力され、クラッシュレポーターライブラリまたはGoogleプロトコルバッファーデコーダーを使用してデコードされる場合があります。
ライブラリ内デコードサポートに加えて、付属のplcrashutilバイナリを使用して、クラッシュレポートをAppleの標準iPhoneテキスト形式に変換できます。
plcrashutil convert -- format = iphone example_report . plcrash atosコマンドラインツールを使用して、出力を象徴することができます。このツールの詳細については、識別可能なシンボル名をクラッシュレポートに追加することを参照してください。将来のライブラリリリースには、電話から直接代替形式を出力するための組み込みの再利用可能なフォーマッタが含まれる場合があります。
Plcrashreporterは、Cocoapods、Carthage、Swift Package Managerを介して、またはプロジェクトにバイナリを手動で追加することにより、アプリに追加できます。
Podfileに追加します。 pod 'PLCrashReporter'pod install実行して、新しく定義されたポッドをインストールし、プロジェクトの.xcworkspaceを開きます。Cartfileに追加します。 github "microsoft/plcrashreporter"carthage update --use-xcframeworks依存関係を取得します。Frameworks, Libraries and Embedded Contentセクションにドラッグアンドドロップします。 iOSおよびTVOの場合、 Do not embedようにEmbed 。 macOSの場合、 Embed and SignにEmbedれて署名します。注: Carthageの統合は、Xcode 12でフラグ「 - No-Use-Binaries」または特定のブランチから依存関係を正しく構築しません。それを機能させるには、この指示を参照してください。
注: Plcrashreporter XCFrameworkには、iOSおよびTVOの静的バイナリ、およびMacOSの動的バイナリが含まれています。フレームワークをプロジェクトに追加するときは
Frameworks, Libraries and Embedded ContentセクションEmbedことを確認してください。iOSおよびTVOSにDo not embedように選択され、MacOSの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リポジトリを参照するか、Homebrewを使用してインストールしてください。ターミナル用の新しいウィンドウを開きます。
Plcrashreporterのルートフォルダーに移動して実行します
xcodebuild -configuration Release -target ' CrashReporter 'すべてのプラットフォームのバイナリを作成します。
protobuf-c依存関係を更新するには:
protobuf-chおよびprotobuf-ccファイルをダウンロードします。Dependencies/protobuf-cでダウンロードしたファイルに置き換えます。./Dependencies/protobuf-c/generate-pb-c.shプルリクエストを介してご紹介を楽しみにしています。
Plcrashreporterに貢献するには、すべてのアーキテクチャ用のplcrashreporterを構築するための上記のツールと、プロトコルバッファー.protoファイルをc記述子コードに変換するためのprotobuf-c必要です。
このプロジェクトは、Microsoftのオープンソース行動規範を採用しています。詳細については、FAQのコードを参照するか、追加の質問やコメントについては[email protected]にお問い合わせください。