PLCRASHRPORTER es una biblioteca de código abierto confiable que proporciona un marco de informes de bloqueo en vivo en proceso para su uso en iOS, MacOS y TVOS. La biblioteca detecta bloqueos y genera informes para ayudar a su investigación y resolución de problemas con la información de aplicación, sistema, proceso, hilo, etc., así como trazas de pila.
La forma más fácil de usar PLCRASHReporter es usar AppCenter. Sin embargo, si desea usar PLCRASHReporter directamente, tome la última versión en la página de lanzamientos.
Los informes de choque se emiten como mensajes codificados por protobuf, y pueden decodificarse utilizando la biblioteca CrashRepter o cualquier decodificador de buffers de protocolo de Google.
Además del soporte de decodificación en biblioteca, puede usar el binario plcrashutil incluido para convertir informes de bloqueo en el formato de texto estándar de iPhone de Apple:
plcrashutil convert -- format = iphone example_report . plcrash Puede usar la herramienta de línea de comandos atos para simbolizar la salida. Para obtener más información sobre esta herramienta, consulte Agregar nombres de símbolos identificables a un informe de bloqueo. Las versiones futuras de la biblioteca pueden incluir formateros reutilizables incorporados, para generar formatos alternativos directamente desde el teléfono.
PLCRASHPERTER se puede agregar a su aplicación a través de Cocoapods, Carthage, Swift Package Manager, o agregando manualmente los binarios a su proyecto.
Podfile : pod 'PLCrashReporter'pod install para instalar su POD recién definido y abra el .xcworkspace del proyecto.Cartfile : github "microsoft/plcrashreporter"carthage update --use-xcframeworks para obtener dependencias.Frameworks, Libraries and Embedded Content . Para iOS y tvos, configure Embed para Do not embed . Para MacOS, configure Embed para Embed and Sign .Nota: La integración de Cartago no construye la dependencia correctamente en Xcode 12 con el indicador "--No-Use-Binaries" o desde una rama específica. Para que funcione, consulte esta instrucción.
Nota: PLCRASHReporter XCFRamework contiene binarios estáticos para iOS y TVOS, y binarios dinámicos para macOS. Al agregar el marco a su proyecto, asegúrese de que en
Frameworks, Libraries and Embedded ContentseEmbedparaDo not embedpara iOS y TVOS eEmbed and Signpara macOS.PLCrashReporter-Static-{version}.zipes una excepción: contiene marcos estáticos para todas las plataformas.
El siguiente ejemplo muestra una forma de inicializar el reportero de choque. Tenga en cuenta que habilitar los informes de accidentes en proceso entrará en conflicto con los depugadores adjuntos, así que asegúrese de que el depurador no esté adjunto cuando bloquee la aplicación.
@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);
}
// }La verificación del informe de choque recopilado se puede hacer de la siguiente manera:
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 ) " )
}
// }La verificación del informe de choque recopilado se puede hacer de la siguiente manera:
// 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 ( ) Además, las próximas herramientas opcionales se utilizan para crear recursos adicionales:
protobuf-c para convertir el búfer de protocolo .proto PROTO AL CÓDIGO DE DESCRIPTOR C. Consulte el repositorio oficial de ProtoBuf-C para obtener más información o use HomeBrew para instalarla.Abra una nueva ventana para su terminal.
Vaya a la carpeta de raíz de plcrashreporter y ejecute
xcodebuild -configuration Release -target ' CrashReporter 'para crear binarios para todas las plataformas.
Para actualizar la dependencia protobuf-c :
protobuf-ch y protobuf-cc desde el repositorio de GitHub ProtoBUf-C.Dependencies/protobuf-c con los descargados../Dependencies/protobuf-c/generate-pb-c.shEsperamos sus contribuciones a través de solicitudes de extracción.
Para contribuir a PLCRASHRPORTER, necesita las herramientas mencionadas anteriormente para construir PLCRASHReporter para todas las arquitecturas y protobuf-c para convertir el búfer de protocolo .proto Archivos de Proto en código descriptor.
Este proyecto ha adoptado el Código de Conducta Open Open Microsoft. Para obtener más información, consulte el Código de Conducta Preguntas frecuentes o comuníquese con [email protected] con cualquier pregunta o comentario adicional.