Own Your Crash Logs with PLCrashReporter: Part 3
In the third post of our PLCrashReporter series, we will walk through how to get PLCrashReporter up and running on your machine. And make sure to check out Part 1 and Part 2 of our series if you haven’t already.
It’s time to install PLCrashReporter and get your first crash report!
Step 1: Download the Library
First, you need to download the latest release of PLCrashReporter to your computer. As of this writing, 1.5.1 is the latest release. Visit the PLCrashReporter releases page and download PLCrashReporter-1.5.1.zip.
You may have noticed another zip file with the word “Static” included in its filename. This is the static library version of PLCrashReporter which we won’t use for this walkthrough. We’ll use the dynamic framework. To learn more about dynamic frameworks versus static libraries check out this BNR blog post on libraries vs frameworks.
Step 2: Set Up the Project
Now that you have the library downloaded, it’s time to put it in an Xcode project.
Open Xcode 12 and create a new iOS app project for this walkthrough. Make sure to use the Swift language with SwiftUI for your app interface, but select to use a UIKit App Delegate for its lifecycle. Name your app “PLCExample.”
Unzip PLCrashReporter-1.5.1.zip and go into the “iOS Framework” folder where you’ll see an item named CrashReporter.framework. Copy and paste it into your project’s directory.
Finally, drag the newly-pasted framework from your project’s directory into your Xcode project. It should look like this:
Now PLCrashReporter is in your project!
Step 3: Add a Bridging Header
Because PLCrashReporter is an Objective-C library, you’ll need to set up a bridging header before you can start playing with it in your Swift project.
The easiest way to create a bridging header is to create a new Objective-C class in Xcode. Xcode will offer to set up the bridging header for you so you just need to accept its offer, then delete the Objective-C class files while keeping the bridging header.
Once you have your bridging header, open it up and add
#import <CrashReporter/CrashReporter.h> This exposes PLCrashReporter to your Swift project.
Step 4: Enable the Crash Reporter
It’s time to start writing some code. To kick things off, you need to enable PLCrashReporter. Open up your AppDelegate and put the following in
let reporter = PLCrashReporter() reporter.enable()
That’s it! You’ve got PLCrashReporter up and running, ready to record crashes. Time to buckle up and crash your app. We will cover this in our next post!