PlCrashReporter adalah perpustakaan open source yang andal yang menyediakan kerangka pelaporan crash langsung dalam proses untuk digunakan di iOS, macOS dan TVOS. Perpustakaan mendeteksi crash dan menghasilkan laporan untuk membantu penyelidikan dan pemecahan masalah Anda dengan informasi aplikasi, sistem, proses, utas, dll. Serta jejak tumpukan.
Cara termudah untuk menggunakan plcrashreporter adalah dengan menggunakan AppCenter. Namun, jika Anda ingin menggunakan PlcrashReporter secara langsung, ambil rilis terbaru di halaman rilis.
Laporan crash adalah output sebagai pesan yang dikodekan protobuf, dan dapat didekodekan menggunakan crashreporter Library atau decoder buffer protokol Google.
Selain dukungan decoding dalam-perpustakaan, Anda dapat menggunakan biner plcrashutil yang disertakan untuk mengonversi laporan crash ke format teks iPhone standar Apple:
plcrashutil convert -- format = iphone example_report . plcrash Anda dapat menggunakan alat garis perintah atos untuk melambangkan output. Untuk informasi lebih lanjut tentang alat ini, lihat Menambahkan Nama Simbol yang Dapat Diidentifikasi ke Laporan Kecelakaan. Rilis perpustakaan di masa depan dapat mencakup format yang dapat digunakan kembali bawaan, untuk mengeluarkan format alternatif langsung dari telepon.
PlCrashReporter dapat ditambahkan ke aplikasi Anda melalui Cocoapods, Carthage, Swift Package Manager, atau dengan secara manual menambahkan binari ke proyek Anda.
Podfile Anda: pod 'PLCrashReporter'pod install untuk menginstal pod Anda yang baru ditentukan dan buka .xcworkspace proyek.Cartfile Anda: github "microsoft/plcrashreporter"carthage update --use-xcframeworks untuk mengambil dependensi.Frameworks, Libraries and Embedded Content . Untuk iOS dan TVOS, set Embed untuk Do not embed . Untuk macOS, atur Embed ke Embed and Sign .Catatan: Integrasi Carthage tidak membangun ketergantungan dengan benar di Xcode 12 dengan bendera "--no-use-binaries" atau dari cabang tertentu. Untuk membuatnya bekerja, lihat instruksi ini.
CATATAN: PlCrashreporter XCFRAMEWork berisi biner statis untuk iOS dan TVOS, dan biner dinamis untuk macOS. Saat menambahkan kerangka kerja ke proyek Anda, pastikan bahwa dalam
Frameworks, Libraries and Embedded ContentEmbeduntukDo not embeduntuk iOS dan TVOS danEmbed and Signuntuk macOS.PLCrashReporter-Static-{version}.zipadalah pengecualian-berisi kerangka kerja statis untuk semua platform.
Contoh berikut menunjukkan cara bagaimana menginisialisasi crash reporter. Harap dicatat bahwa memungkinkan pelaporan crash dalam proses akan bertentangan dengan debugger terlampir jadi pastikan debugger tidak terlampir saat Anda menghancurkan aplikasi.
@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);
}
// }Memeriksa Laporan Kecelakaan yang dikumpulkan dapat dilakukan dengan cara berikut:
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 ) " )
}
// }Memeriksa Laporan Kecelakaan yang dikumpulkan dapat dilakukan dengan cara berikut:
// 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 ( ) Juga, alat opsional berikutnya digunakan untuk membangun sumber daya tambahan:
protobuf-c untuk mengonversi buffer protokol .proto File ke kode deskriptor C. Lihat Repositori Protobuf-C Resmi untuk informasi lebih lanjut atau gunakan Homebrew untuk menginstalnya.Buka jendela baru untuk terminal Anda.
Pergi ke folder root plcrashreporter dan jalankan
xcodebuild -configuration Release -target ' CrashReporter 'Untuk membuat binari untuk semua platform.
Untuk memperbarui ketergantungan protobuf-c :
protobuf-ch dan protobuf-cc terbaru dari repositori Github Protobuf-C.Dependencies/protobuf-c dengan yang diunduh../Dependencies/protobuf-c/generate-pb-c.shKami menantikan kontribusi Anda melalui permintaan tarik.
Untuk berkontribusi pada PlcrashReporter, Anda memerlukan alat yang disebutkan di atas untuk membangun Plcrashreporter untuk semua arsitektur dan protobuf-c untuk mengonversi buffer protokol .proto file ke kode deskriptor C.
Proyek ini telah mengadopsi kode perilaku open source Microsoft. Untuk informasi lebih lanjut, lihat FAQ Kode Perilaku atau hubungi [email protected] dengan pertanyaan atau komentar tambahan.