Swiftpack.co - honeybadger-io/honeybadger-cocoa as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by honeybadger-io.
honeybadger-io/honeybadger-cocoa 0.0.3
Official Objective-C & Swift library for reporting errors and crashes to Honeybadger.io :apple: :zap:
⭐️ 1
🕓 19 weeks ago
iOS macOS
.package(url: "https://github.com/honeybadger-io/honeybadger-cocoa.git", from: "0.0.3")

Honeybadger for iOS and MacOS

An SDK for integrating Honeybadger into your iOS and MacOS apps. This SDK can be used in both Swift and Objective-C projects.

Installation

SwiftPM compatible CocoaPods compatible

CocoaPods

To install via CocoaPods, create/open your Pods file and add a pod entry for 'Honeybadger'. Make sure use_frameworks! is specified.

use_frameworks!

target 'MyApp' do
	pod 'Honeybadger'
end

Swift Package Manager

Open your app in Xcode, then go to File > Swift Packages > Add Package Dependency, and specify the Honeybadger Cocoa GitHub repo: https://github.com/honeybadger-io/honeybadger-cocoa

Initialization

You will need your Honeybadger API key to initialize the Honeybadger library. You can log into your Honeybadger account to obtain your API key.

In your App Delegate, import the Honeybadger library:

Swift

import Honeybadger

Objective-C

@import Honeybadger;

In your didFinishLaunchingWithOptions method, add the following code to initialize Honeybadger:

Swift

Honeybadger.configure(apiKey:"Your Honeybadger API key")

Objective-C

[Honeybadger configureWithAPIKey:@"Your Honeybadger API key"];

Usage Examples

Errors and exceptions will be automatically handled by the Honeybadger library, but you can also use the following API to customize error handling in your application.

notify

You can use the notify methods to manually send an error as a string or Error/NSError object. If available, the Honeybadger library will attempt to extract a stack trace and any relevant information that might be useful. You can also optionally provide context, to include any relevant information about the error.

Swift


Honeybadger.notify(
	errorString: "My error"
);

Honeybadger.notify(
	errorString: "My error", 
	context: ["user_id" : "123abc"]
);

Honeybadger.notify(
	error: MyError("This is my custom error.")
);

Honeybadger.notify(
	error: MyError("This is my custom error."), 
	context: ["user_id" : "123abc"]
);

Objective-C

[Honeybadger notifyWithString:@"My error"];

[Honeybadger 
	notifyWithString:@"My error" 
	context:@{ @"user_id" : @"123abc" }
];

[Honeybadger notifyWithError:
	[[NSError alloc] initWithDomain:@"my.test.error" code:-1 userInfo: @{}]
];

[Honeybadger 
	notifyWithError:[[NSError alloc] initWithDomain:@"my.test.error" code:-1 userInfo: @{}]
	context:@{ @"user_id" : @"123abc" }
];

setContext

If you have data that you would like to include whenever an error or an exception occurs, you can provide that data using the setContext method. You can call setContext as many times as needed. New context data will be merged with any previously-set context data.

Swift

Honeybadger.setContext(context: ["user_id" : "123abc"]);

Objective-C

[Honeybadger setContext:@{@"user_id" : @"123abc"}];

resetContext

If you've used setContext to store data, you can use resetContext to clear that data.

Swift

Honeybadger.resetContext();

Objective-C

[Honeybadger setContext];

License

The Honeybadger iOS/MacOS SDK is MIT-licensed. See the LICENSE file in this repository for details.

GitHub

link
Stars: 1
Last commit: 19 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Initial public release
23 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics