Crashlife 1.0.2

Crashlife 1.0.2

Maintained by Daniel DeCovnick, Dave Schukin.



Crashlife 1.0.2

  • By
  • Buglife

Platform CocoaPods Compatible Carthage compatible License Twitter

Crashlife is an awesome crash reporting SDK & web platform for iOS apps. Here's how it works:

  1. Your app crashes and relaunches
  2. Crashlife sends the crash report to the Crashlife web dashboard
  3. There is no step 3.

You can also find Crashlife for Android here.


Main Features
πŸ“– Open source
πŸƒπŸ½β€β™€οΈ Fast & lightweight
πŸ“œ Custom attributes
ℹ️ Captured footprints and logs, with info / warning / error levels
πŸ‘©πŸ½β€πŸ’» Written in Objective-C, with full Swift support

Installation

CocoaPods

To integrate Buglife into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'Crashlife'

Then, run the following command:

$ pod install

Carthage

Place the following line in your Cartfile:

github "Buglife/Crashlife-iOS"

Now run carthage update. Then drag & drop the Crashlife.framework in the Carthage/build folder to your project. Refer to the Carthage README for detailed / updated instructions.

Code

  1. Import the Crashlife framework header into your app delegate.

    // Swift
    import Crashlife
    // Objective-C
    #import <Crashlife/Crashlife.h>
  2. Add the following to your app delegate's application:didFinishLaunchingWithOptions: method.

    // Swift
    Crashlife.shared.start(withAPIKey: "YOUR_API_KEY_HERE")
    // Objective-C
    [[Crashlife sharedCrashlife] startWithAPIKey:@"YOUR_API_KEY_HERE"];

    Be sure to replace YOUR_API_KEY_HERE with your own API key.

  3. Build & run your app, then crash it (hopefully deliberately)! Note that the crash reporter will not activate for most crashes if the app was started attached to a debugger.

  4. On relaunch, your crash will be submitted; then go to the Crashlife web dashboard.

Usage

Crash Reporting

Once initialized, Crashlife will watch for uncaught exceptions (C++, ObjC), as well as Mach and POSIX signals. Crash reports will be saved to disk and sent on next launch. If the crash report can't be submitted for any reason, it will persist on disk until it can be sent at launch.

Additionally, Crashlife supports logging caught exceptions and error, warning, and info messages to the web dashboard as individual events.

Caught exception reporting

Crashlife can log caught exceptions will a full stack trace. From your catch block, call

// Swift
Crashlife.shared.logException(anNSException)
// Objective-C
[[Crashlife sharedCrashlife] logException:anNSException];

You can also pass a new (not yet-thrown) exception, however for performance reasons, it will not contain a stack trace. Crashlife will attempt to send the exception event immediately, and will cache it in case it is unable to do so.

Error/Warning/Info events

Crashlife supports logging messages of the severity of your choice: Crash, Error, Warning, and Info.

// Log an NSError
Crashlife.shared.logErrorObject(anNSError)

// Log an error
Crashlife.shared.logError("An error occurred: ...")

// Log a warning
Crashlife.shared.logWarning("Warning: doing something dangerous...")

// Log an informational message
Crashlife.shared.logInfo("Note: something weird is going on...")
// Objective-C
[[Crashlife sharedCrashlife] logErrorObject:error];

[[Crashlife sharedCrashlife] logError:@"An error occurred..."];

[[Crashlife sharedCrashlife] logWarning:@"Warning: doing something dangerous..."];

[[Crashlife sharedCrashlife] logInfo:@"Note: something weird is going on..."];

Footprints

In order to aid in reproducing crashes, you can include footprints indicating what code paths were followed in order to reach the crash or error. These footprints can include their own attributes to avoid cluttering up the custom attributes. These footprints will not be sent to the Crashlife web dashboard unless a report is made.

// Leave a footprint with no metadata
Crashlife.shared.leaveFootprint("User navigated to screen 2")

// Leave a footprint with metadata
var attributes = [:]
attributes["Developer"] = "You"
attributes["App"] = "Awesome"
Crashlife.shared.leaveFootprint("User did something else", withMetadata:attributes)
// Objective-C
[[Crashlife sharedCrashlife] leaveFootprint:@"User navigated to screen 2"];

NSDictionary<NSString *, NSString *> *attributes = @{@"Developer" : @"You", @"App" : @"Awesome"};
[[Crashlife sharedCrashlife] leaveFootprint:@"User did something else" withMetadata:attributes];

Custom Attributes

Adding custom attributes

You can include custom attributes (i.e. key-value pairs) to your crash reports and logged events, as such:

// Swift
Crashlife.shared.setStringValue("2Pac", forAttribute:"Artist")
Crashlife.shared.setStringValue("California Love", forAttribute:"Song")
// Objective-C
[[Crashlife sharedCrashlife] setStringValue:@"2Pac" forAttribute:@"Artist"];
[[Crashlife sharedCrashlife] setStringValue:@"California Love" forAttribute:@"Song"];


#### Removing attributes

To clear an attribute, set its value to nil.

```swift
Crashlife.shared.setStringValue(nil, forAttribute:"Artist")
[[Crashlife sharedCrashlife] setStringValue:nil forAttribute:@"Artist"];

User Identification

You may set a string representing the user’s name, database ID or other identifier:

let username = ... // the current username
Crashlife.shared.setUserIdentifier(username)
NSString *username = ...;
[[Crashlife sharedCrashlife] setUserIdentifier:username];

Requirements

  • Xcode 8 or later
  • iOS 9 or later

Contributing

We don't have any contributing guidelines at the moment, but feel free to submit pull requests & file issues within GitHub!

License

Copyright (C) 2019 Buglife, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.