|
13 | 13 |
|
14 | 14 | ## Minimal usage |
15 | 15 |
|
16 | | -### Register the `BacktraceClient` using `register(endpoint:,token:)` method and then send error/exception just by calling method `send`: |
| 16 | +### Create the `BacktraceClient` using `init(credentials:)` initializer and then send error/exception just by calling method `send`: |
17 | 17 |
|
18 | 18 | - Swift |
19 | 19 | ```swift |
20 | | - import UIKit |
21 | | - import Backtrace |
22 | | - |
23 | | - @UIApplicationMain |
24 | | - class AppDelegate: UIResponder, UIApplicationDelegate { |
25 | | - |
26 | | - var window: UIWindow? |
27 | | - |
28 | | - func application(_ application: UIApplication, |
29 | | - didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { |
30 | | - let backtraceCredentials = BacktraceCredentials(endpoint: URL(string: "")!, |
31 | | - token: "") |
32 | | - BacktraceClient.shared.register(credentials: backtraceCredentials) |
33 | | - |
34 | | - do { |
35 | | - try throwingFunc() |
36 | | - } catch { |
37 | | - BacktraceClient.shared.send { (result) in |
38 | | - print(result) |
39 | | - } |
40 | | - } |
41 | | - |
42 | | - return true |
43 | | - } |
44 | | - } |
| 20 | +import UIKit |
| 21 | +import Backtrace |
| 22 | + |
| 23 | +@UIApplicationMain |
| 24 | +class AppDelegate: UIResponder, UIApplicationDelegate { |
| 25 | + |
| 26 | + var window: UIWindow? |
| 27 | + |
| 28 | + func application(_ application: UIApplication, |
| 29 | + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { |
| 30 | + |
| 31 | + let backtraceCredentials = BacktraceCredentials(endpoint: URL(string: "https://backtrace.io")!, |
| 32 | + token: "token") |
| 33 | + BacktraceClient.shared = try? BacktraceClient(credentials: backtraceCredentials) |
| 34 | + |
| 35 | + do { |
| 36 | + try throwingFunc() |
| 37 | + } catch { |
| 38 | + BacktraceClient.shared?.send { (result) in |
| 39 | + print(result) |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + return true |
| 44 | + } |
| 45 | +} |
45 | 46 | ``` |
46 | 47 |
|
47 | 48 | - Objective-C |
48 | 49 | ```objective-c |
49 | | - #import "AppDelegate.h" |
50 | | - @import Backtrace; |
| 50 | +#import "AppDelegate.h" |
| 51 | +@import Backtrace; |
51 | 52 |
|
52 | | - @interface AppDelegate () |
| 53 | +@interface AppDelegate () |
53 | 54 |
|
54 | | - @end |
| 55 | +@end |
55 | 56 |
|
56 | | - @implementation AppDelegate |
| 57 | +@implementation AppDelegate |
57 | 58 |
|
58 | | - - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { |
| 59 | +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { |
| 60 | + |
59 | 61 | BacktraceCredentials *credentials = [[BacktraceCredentials alloc] |
60 | | - initWithEndpoint: [NSURL URLWithString: @""] |
61 | | - token: @""]; |
62 | | - [BacktraceClient.shared registerWithCredentials: credentials]; |
| 62 | + initWithEndpoint: [NSURL URLWithString: @"https://backtrace.io"] |
| 63 | + token: @"token"]; |
| 64 | + BacktraceClient.shared = [[BacktraceClient alloc] initWithCredentials: credentials error: nil]; |
63 | 65 |
|
64 | 66 | // sending NSException |
65 | 67 | @try { |
|
80 | 82 | }]; |
81 | 83 |
|
82 | 84 | return YES; |
83 | | - } |
| 85 | +} |
84 | 86 |
|
85 | | - @end |
| 87 | +@end |
86 | 88 | ``` |
87 | 89 |
|
88 | 90 | # Features Summary <a name="features-summary"></a> |
@@ -116,11 +118,60 @@ Register to Backtrace services using provided submission url (see: <a href="http |
116 | 118 |
|
117 | 119 | - Swift |
118 | 120 | ```swift |
119 | | -BacktraceClient.shared.register(credentials: BacktraceCredentials) |
| 121 | +BacktraceClient.shared = try? BacktraceClient(credentials: BacktraceCredentials) |
120 | 122 | ``` |
121 | 123 | - Objective-C |
122 | 124 | ```objective-c |
123 | | -[[BacktraceClient shared] registerWithCredentials: BacktraceCredentials]; |
| 125 | +BacktraceClient.shared = [[BacktraceClient alloc] initWithCredentials: BacktraceCredentials error: error]; |
| 126 | +``` |
| 127 | +
|
| 128 | +## Backtrace client configuration |
| 129 | +For more advanced usage of BacktraceClient, you can supply BacktraceClientConfiguration as a parameter. See the following example: |
| 130 | +```swift |
| 131 | +let backtraceCredentials = BacktraceCredentials(endpoint: URL(string: "https://backtrace.io")!, |
| 132 | + token: "token") |
| 133 | +let configuration = BacktraceClientConfiguration(credentials: backtraceCredentials, |
| 134 | + dbSettings: BacktraceDatabaseSettings(), |
| 135 | + reportsPerMin: 10) |
| 136 | +BacktraceClient.shared = try? BacktraceClient(configuration: configuration) |
| 137 | +``` |
| 138 | + |
| 139 | +### Database settings |
| 140 | +BacktraceClient allows you to customize the initialization of BacktraceDatabase for local storage of error reports by supplying a BacktraceDatabaseSettings parameter, as follows: |
| 141 | +```swift |
| 142 | +let backtraceCredentials = BacktraceCredentials(endpoint: URL(string: "https://backtrace.io")!, |
| 143 | + token: "token") |
| 144 | +let backtraceDatabaseSettings = BacktraceDatabaseSettings() |
| 145 | +backtraceDatabaseSettings.maxRecordCount = 1000 |
| 146 | +backtraceDatabaseSettings.maxDatabaseSize = 10 |
| 147 | +backtraceDatabaseSettings.retryInterval = 5 |
| 148 | +backtraceDatabaseSettings.retryLimit = 3 |
| 149 | +backtraceDatabaseSettings.retryBehaviour = RetryBehaviour.interval |
| 150 | +backtraceDatabaseSettings.retryOrder = RetryOder.queue |
| 151 | +let backtraceConfiguration = BacktraceClientConfiguration(credentials: backtraceCredentials, |
| 152 | + dbSettings: backtraceDatabaseSettings, |
| 153 | + reportsPerMin: 10) |
| 154 | +BacktraceClient.shared = try? BacktraceClient(configuration: backtraceConfiguration) |
| 155 | +``` |
| 156 | + |
| 157 | +### Events handling |
| 158 | +BacktraceClient allows you to subscribe for events produced before and after sending error report: |
| 159 | +- Swift |
| 160 | +```swift |
| 161 | +BacktraceClient.shared?.delegate = self |
| 162 | + |
| 163 | +func willSend(_ report: BacktraceCrashReport) -> (BacktraceCrashReport) |
| 164 | +func willSendRequest(_ request: URLRequest) -> URLRequest |
| 165 | +func serverDidFail(_ error: Error) |
| 166 | +func serverDidResponse(_ result: BacktraceResult) |
| 167 | +func didReachLimit(_ result: BacktraceResult) |
| 168 | +``` |
| 169 | + |
| 170 | +### User attributes |
| 171 | +You can add custom user attributes that should be send alongside crash and erros/exceptions: |
| 172 | +- Swift |
| 173 | +```swift |
| 174 | +BacktraceClient.shared?.userAttributes = ["foo": "bar", "testing": true] |
124 | 175 | ``` |
125 | 176 |
|
126 | 177 | ## Backtrace client configuration |
@@ -186,24 +237,6 @@ Registered `BacktraceClient` will be able to send an crash reports. Error report |
186 | 237 | - (void) sendWithException: NSException completion: (void (^)(BacktraceResult * _Nonnull)) completion; |
187 | 238 | ``` |
188 | 239 |
|
189 | | -# Architecture <a name="architecture"></a> |
190 | | - |
191 | | -The library is written in pure Swift and Objective-C is fully supported as Swift codebase can be automatically exposed just by adding annotations: |
192 | | - |
193 | | -```swift |
194 | | -// pure swift class - cannot be exposed to Objective-C |
195 | | -class PureSwiftClass { |
196 | | - |
197 | | -} |
198 | | - |
199 | | -// swift class with Objective-C support |
200 | | -@objc class SwiftClass: NSObject { |
201 | | - |
202 | | -} |
203 | | -``` |
204 | | - |
205 | | -As Swift is meant to be open-source and platform independent the library relies on `protocols` which allows to provide default implementation but simultaneously gives you a lot of place for customisation. |
206 | | - |
207 | 240 | # FAQ |
208 | 241 | ## Missing dSYM files |
209 | 242 | Make sure your project is configured to generate the debug symbols: |
|
0 commit comments