PlcrashReporter เป็นห้องสมุดโอเพนซอร์สที่เชื่อถือได้ซึ่งให้กรอบการรายงานการล่มสลายในระหว่างกระบวนการสำหรับใช้บน iOS, MacOS และ TVOS ห้องสมุดตรวจพบการขัดข้องและสร้างรายงานเพื่อช่วยในการตรวจสอบและแก้ไขปัญหาด้วยข้อมูลของแอปพลิเคชันระบบกระบวนการเธรด ฯลฯ รวมถึงร่องรอยสแต็ก
วิธีที่ง่ายที่สุดในการใช้ plcrashreporter คือการใช้ AppCenter อย่างไรก็ตามหากคุณต้องการใช้ plcrashreporter โดยตรงให้คว้ารุ่นล่าสุดที่หน้าเผยแพร่
รายงานความผิดพลาดจะถูกส่งออกเป็นข้อความที่เข้ารหัส protobuf และอาจถูกถอดรหัสโดยใช้ไลบรารี CrashReporter หรือตัวถอดรหัสบัฟเฟอร์ของ Google Protocol
นอกเหนือจากการสนับสนุนการถอดรหัสในห้องสมุดแล้วคุณสามารถใช้ plcrashutil Binary ที่ให้ไว้เพื่อแปลงรายงานการขัดข้องเป็นรูปแบบข้อความ iPhone มาตรฐานของ Apple:
plcrashutil convert -- format = iphone example_report . plcrash คุณสามารถใช้เครื่องมือบรรทัดคำสั่ง atos เพื่อเป็นสัญลักษณ์ของเอาต์พุต สำหรับข้อมูลเพิ่มเติมเกี่ยวกับเครื่องมือนี้ดูการเพิ่มชื่อสัญลักษณ์ที่ระบุตัวตนลงในรายงานความผิดพลาด การเผยแพร่ห้องสมุดในอนาคตอาจรวมถึงตัวสร้างใหม่ในตัวสำหรับการส่งออกรูปแบบทางเลือกโดยตรงจากโทรศัพท์
Plcrashreporter สามารถเพิ่มลงในแอพของคุณผ่าน Cocoapods, Carthage, Swift Package Manager หรือโดยการเพิ่มไบนารีลงในโครงการของคุณด้วยตนเอง
Podfile ของคุณ: pod 'PLCrashReporter'pod install เพื่อติดตั้ง POD ที่กำหนดไว้ใหม่ของคุณและเปิด .xcworkspace ของโครงการCartfile ของคุณ: github "microsoft/plcrashreporter"carthage update --use-xcframeworks เพื่อดึงข้อมูลขึ้นมาFrameworks, Libraries and Embedded Content สำหรับ iOS และ TVOS ตั้ง Embed ให้ Do not embed สำหรับ macOS ให้ตั้ง Embed เป็น Embed and Signหมายเหตุ: การรวม Carthage ไม่ได้สร้างการพึ่งพาอย่างถูกต้องใน Xcode 12 ด้วยการตั้งค่าสถานะ "-ไม่มีการใช้ไบนารีการใช้งาน" หรือจากสาขาเฉพาะ เพื่อให้มันใช้งานได้โปรดดูคำแนะนำนี้
หมายเหตุ: Plcrashreporter XCFramework มีไบนารีคงที่สำหรับ iOS และ TVOS และไบนารีแบบไดนามิกสำหรับ MacOS เมื่อเพิ่มเฟรมเวิร์กลงในโครงการของคุณตรวจสอบให้แน่ใจว่าใน
Frameworks, Libraries and Embedded ContentEmbedถูกเลือกให้Do not embedสำหรับ iOS และ TVOS และEmbed and Signใน MacOSPLCrashReporter-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 proto ไฟล์เป็นรหัส descriptor c ดูที่เก็บข้อมูลอย่างเป็นทางการ Protobuf-C สำหรับข้อมูลเพิ่มเติมหรือใช้ Homebrew เพื่อติดตั้งเปิดหน้าต่างใหม่สำหรับเทอร์มินัลของคุณ
ไปที่โฟลเดอร์รูทของ Plcrashreporter แล้วเรียกใช้
xcodebuild -configuration Release -target ' CrashReporter 'เพื่อสร้างไบนารีสำหรับทุกแพลตฟอร์ม
เพื่ออัปเดตการพึ่งพา protobuf-c :
protobuf-ch และ protobuf-cc ล่าสุดจากที่เก็บ protobuf-c githubDependencies/protobuf-c ด้วยไฟล์ที่ดาวน์โหลด./Dependencies/protobuf-c/generate-pb-c.shเรารอคอยการมีส่วนร่วมของคุณผ่านคำขอดึง
ในการมีส่วนร่วมใน plcrashreporter คุณต้องใช้เครื่องมือที่กล่าวถึงข้างต้นเพื่อสร้าง plcrashreporter สำหรับสถาปัตยกรรมทั้งหมดและ protobuf-c เพื่อแปลงบัฟเฟอร์โปรโตคอลไฟล์ .proto เป็นรหัส descriptor c
โครงการนี้ได้นำรหัสการดำเนินงานของ Microsoft โอเพ่นซอร์สมาใช้ สำหรับข้อมูลเพิ่มเติมโปรดดูจรรยาบรรณคำถามที่พบบ่อยหรือติดต่อ [email protected] พร้อมคำถามหรือความคิดเห็นเพิ่มเติมใด ๆ