PlcrashReporter est une bibliothèque open source fiable qui fournit un framework de rapport de crash en direct dans le processus à utiliser sur iOS, macOS et TVOS. La bibliothèque détecte des plantages et génère des rapports pour aider votre enquête et dépanner avec les informations de l'application, du système, du processus, du thread, etc. ainsi que des traces de pile.
La façon la plus simple d'utiliser PlcrashReporter est d'utiliser AppCenter. Cependant, si vous souhaitez utiliser PlcrashReporter directement, prenez la dernière version sur la page des versions.
Les rapports de crash sont sortis sous forme de messages codés par Protobuf et peuvent être décodés à l'aide de la bibliothèque CrashReporter ou de tout décodeur de tampons de protocole Google.
En plus du support de décodage en bibliothèque, vous pouvez utiliser le binaire plcrashutil inclus pour convertir les rapports de crash au format de texte de l'iPhone d'Apple:
plcrashutil convert -- format = iphone example_report . plcrash Vous pouvez utiliser l'outil de ligne de commande atos pour symboliquer la sortie. Pour plus d'informations sur cet outil, voir l'ajout de noms de symboles identifiables à un rapport de crash. Les versions futures de la bibliothèque peuvent inclure des formateurs réutilisables intégrés, pour sortir des formats alternatifs directement à partir du téléphone.
Plcrashreporter peut être ajouté à votre application via Cocoapods, Carthage, Swift Package Manager ou en ajoutant manuellement les binaires à votre projet.
Podfile : pod 'PLCrashReporter'pod install pour installer votre pod nouvellement défini et ouvrir le .xcworkspace du projet.Cartfile : github "microsoft/plcrashreporter"carthage update --use-xcframeworks pour récupérer les dépendances.Frameworks, Libraries and Embedded Content . Pour iOS et TVOS, définissez Embed pour Do not embed . Pour macOS, définissez Embed sur Embed and Sign .Remarque: Carthage Intégration ne construit pas correctement la dépendance dans Xcode 12 avec Flag "--No-Use-Binaries" ou à partir d'une branche spécifique. Pour le faire fonctionner, reportez-vous à cette instruction.
Remarque: PLCRashReporter XCFramework contient des binaires statiques pour iOS et TVOS et des binaires dynamiques pour macOS. Lorsque vous ajoutez le cadre à votre projet, assurez-vous que dans
Frameworks, Libraries and Embedded ContentEmbedest sélectionnée pourDo not embedpour iOS et TVOS etEmbed and Signpour macOS.PLCrashReporter-Static-{version}.zipest une exception - il contient des frameworks statiques pour toutes les plates-formes.
L'exemple suivant montre un moyen d'initialiser Crash Reporter. Veuillez noter que l'activation des rapports de crash en cours entre en conflit entrera avec tous les débuggeurs ci-joints, alors assurez-vous que le débogueur n'est pas joint lorsque vous bloquez l'application.
@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 vérification du rapport de crash collecté peut être effectuée de la manière suivante:
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 vérification du rapport de crash collecté peut être effectuée de la manière suivante:
// 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 ( ) De plus, les prochains outils facultatifs sont utilisés pour créer des ressources supplémentaires:
protobuf-c pour convertir les fichiers de tampon de protocole .proto en code de descripteur C. Consultez le référentiel officiel Protobuf-C pour plus d'informations ou utilisez Homebrew pour l'installer.Ouvrez une nouvelle fenêtre pour votre terminal.
Allez dans le dossier racine de Plcrashreporter et courez
xcodebuild -configuration Release -target ' CrashReporter 'pour créer des binaires pour toutes les plateformes.
Pour mettre à jour la dépendance protobuf-c :
protobuf-ch et protobuf-cc à partir du référentiel GitHub Protobuf-C.Dependencies/protobuf-c par ceux téléchargés../Dependencies/protobuf-c/generate-pb-c.shNous attendons avec impatience vos contributions via des demandes de traction.
Pour contribuer à PlcrashReporter, vous avez besoin des outils mentionnés ci-dessus pour construire PlcrashReporter pour toutes les architectures et protobuf-c pour convertir des fichiers de tampon de protocole .proto en code de descripteur.
Ce projet a adopté le code de conduite open source Microsoft. Pour plus d'informations, consultez le code de conduite FAQ ou contactez [email protected] avec toute question ou commentaire supplémentaire.