Skip to content

backtrace-labs/backtrace-cocoa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Backtrace Integration with iOS

Supported platforms Supported languages CocoaPods compatible License: MIT Build Status

Backtrace's integration with iOS, macOS, and tvOS applications allows you to capture and report handled and unhandled exceptions so you can prioritize and debug software errors.

Installation

You can use this SDK through either Swift Package Manager or CocoaPods. The SPM package can be integrated directly within Xcode or by editing your package's Package.swift file.
Choose one of the following integration methods.

Via Xcode

  1. In File > Add Packages, search for and add https://github.com/backtrace-labs/backtrace-cocoa.git
  2. Verify your project Package Dependencies list backtrace-cocoa.
  3. Add Backtrace to your target’s Frameworks, Libraries, and Embedded Content.

Via Package.swift

Add this dependency to your Package.swift file:

.package(url: "https://github.com/backtrace-labs/backtrace-cocoa.git)

Via CocoaPods

Add the following to your Podfile:

  • Specify use_frameworks!.

  • Add the Backtrace pod:

    pod 'Backtrace'
    

Via Multiplatform Binary Framework Bundle

  1. Obtain and Unarchive Backtrace binary frameworks

  2. Add Backtrace multiplatform binary framework bundle to your project using the method that best fits your workflow:

    • Drag & drop .framework or .xcframework from Finder into Xcode's Project Navigator and check the Target Membership setting
    • Using Swift Package Manager's binaryTarget flag
    • Using CocoaPods's vendored_frameworks flag

    Note: Backtrace multiplatform binary framework contains Mach-O 64-bit dynamic binaries for iOS, macOS, Mac Catalyst and tvOS. When adding Backtrace to your project, set Frameworks, Libraries and Embedded Content section to Embed. PLCrashReporter multiplatform binary framework contains static binaries, set Frameworks, Libraries and Embedded Content section to Do Not Embed.

Usage

Swift

let backtraceCredentials = BacktraceCredentials(endpoint: URL(string: Keys.backtraceUrl as String)!,
token: Keys.backtraceToken as String)
let backtraceDatabaseSettings = BacktraceDatabaseSettings()
backtraceDatabaseSettings.maxRecordCount = 10
let backtraceConfiguration = BacktraceClientConfiguration(credentials: backtraceCredentials,
dbSettings: backtraceDatabaseSettings,
reportsPerMin: 10,
allowsAttachingDebugger: true,
detectOOM: true)
BacktraceClient.shared = try? BacktraceClient(configuration: backtraceConfiguration)
BacktraceClient.shared?.attributes = ["foo": "bar", "testing": true]
BacktraceClient.shared?.attachments.append(fileUrl)
do {
try throwingFunc()
} catch {
BacktraceClient.shared?.send(attachmentPaths: []) { (result) in
print("AppDelegate:Result:\(result)")
}
}

Objective-C

BacktraceCredentials *credentials = [[BacktraceCredentials alloc]
initWithEndpoint: [NSURL URLWithString: Keys.backtraceUrl]
token: [Keys backtraceToken]];
BacktraceDatabaseSettings *backtraceDatabaseSettings = [[BacktraceDatabaseSettings alloc] init];
backtraceDatabaseSettings.maxRecordCount = 10;
BacktraceClientConfiguration *configuration = [[BacktraceClientConfiguration alloc]
initWithCredentials: credentials
dbSettings: backtraceDatabaseSettings
reportsPerMin: 3
allowsAttachingDebugger: TRUE
detectOOM: TRUE];
BacktraceClient.shared = [[BacktraceClient alloc] initWithConfiguration: configuration error: nil];
BacktraceClient.shared.attributes = @{@"foo": @"bar", @"testing": @YES};
BacktraceClient.shared.attachments = [NSArray arrayWithObjects:fileUrl, nil];
// sending NSException
@try {
NSArray *array = @[];
array[1]; // will throw exception
} @catch (NSException *exception) {
[[BacktraceClient shared] sendWithAttachmentPaths: [NSArray init] completion: ^(BacktraceResult * _Nonnull result) {
NSLog(@"%@", result);
}];
} @finally {
}

Documentation

For more information about the iOS SDK, including installation, usage, and configuration options, see the iOS Integration guide in the Sauce Labs documentation.