Skip to content

Commit 8551020

Browse files
author
vlussenburg
committed
Updated exampleApp code to be used for documentation
1 parent afcee7f commit 8551020

File tree

3 files changed

+31
-42
lines changed

3 files changed

+31
-42
lines changed

Examples/Example-iOS-ObjC/AppDelegate.m

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,47 @@ @interface AppDelegate () <BacktraceClientDelegate>
1010
@implementation AppDelegate
1111

1212
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
13+
NSArray *paths = @[[[NSBundle mainBundle] pathForResource: @"test" ofType: @"txt"]];
14+
NSString *fileName = @"myCustomFile.txt";
15+
NSURL *libraryUrl = [[[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory
16+
inDomains:NSUserDomainMask] lastObject];
17+
NSURL *fileUrl = [libraryUrl URLByAppendingPathComponent:fileName];
18+
1319
BacktraceCredentials *credentials = [[BacktraceCredentials alloc]
1420
initWithEndpoint: [NSURL URLWithString: Keys.backtraceUrl]
1521
token: [Keys backtraceToken]];
1622
BacktraceDatabaseSettings *backtraceDatabaseSettings = [[BacktraceDatabaseSettings alloc] init];
17-
backtraceDatabaseSettings.maxRecordCount = 1000;
18-
backtraceDatabaseSettings.maxDatabaseSize = 10;
19-
backtraceDatabaseSettings.retryInterval = 5;
20-
backtraceDatabaseSettings.retryLimit = 3;
21-
backtraceDatabaseSettings.retryBehaviour = RetryBehaviourInterval;
22-
backtraceDatabaseSettings.retryOrder = RetryOrderStack;
23-
23+
backtraceDatabaseSettings.maxRecordCount = 10;
24+
2425
BacktraceClientConfiguration *configuration = [[BacktraceClientConfiguration alloc]
2526
initWithCredentials: credentials
2627
dbSettings: backtraceDatabaseSettings
2728
reportsPerMin: 3
2829
allowsAttachingDebugger: TRUE
2930
detectOOM: TRUE];
3031
BacktraceClient.shared = [[BacktraceClient alloc] initWithConfiguration: configuration error: nil];
31-
BacktraceClient.shared.delegate = self;
32-
[BacktraceClient.shared enableBreadcrumbs];
33-
32+
BacktraceClient.shared.attributes = @{@"foo": @"bar", @"testing": @YES};
33+
BacktraceClient.shared.attachments = [NSArray arrayWithObjects:fileUrl, nil];
34+
3435
// sending NSException
3536
@try {
3637
NSArray *array = @[];
37-
NSObject *object = array[1]; // will throw exception
38+
array[1]; // will throw exception
3839
} @catch (NSException *exception) {
39-
NSArray *paths = @[[[NSBundle mainBundle] pathForResource: @"test" ofType: @"txt"]];
40-
[[BacktraceClient shared] sendWithAttachmentPaths: paths completion: ^(BacktraceResult * _Nonnull result) {
40+
[[BacktraceClient shared] sendWithAttachmentPaths: [NSArray init] completion: ^(BacktraceResult * _Nonnull result) {
4141
NSLog(@"%@", result);
4242
}];
4343
} @finally {
4444

4545
}
4646

4747
//sending NSError
48-
NSError *error = [NSError errorWithDomain: @"backtrace.domain" code: 100 userInfo: @{}];
49-
NSArray *paths = @[[[NSBundle mainBundle] pathForResource: @"test" ofType: @"txt"]];
5048
[[BacktraceClient shared] sendWithAttachmentPaths: paths completion: ^(BacktraceResult * _Nonnull result) {
5149
NSLog(@"%@", result);
5250
}];
5351

54-
55-
52+
BacktraceClient.shared.delegate = self;
53+
[BacktraceClient.shared enableBreadcrumbs];
5654
NSDictionary *attributes = @{@"My Attribute":@"My Attribute Value"};
5755
[[BacktraceClient shared] addBreadcrumb:@"My Native Breadcrumb"
5856
attributes:attributes

Examples/Example-iOS-ObjC/ViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ - (IBAction) liveReportAction: (id) sender {
3333

3434
- (IBAction) crashAction: (id) sender {
3535
NSArray *array = @[];
36-
NSObject *o = array[1];
36+
array[1];
3737
}
3838

3939

Examples/Example-iOS/AppDelegate.swift

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ func throwingFunc() throws {
1111

1212
@UIApplicationMain
1313
final class AppDelegate: UIResponder, UIApplicationDelegate {
14-
14+
15+
let fileUrl = createAndWriteFile("sample.txt")
16+
1517
var window: UIWindow?
1618

1719
func application(_ application: UIApplication,
@@ -20,38 +22,29 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
2022
token: Keys.backtraceToken as String)
2123

2224
let backtraceDatabaseSettings = BacktraceDatabaseSettings()
23-
backtraceDatabaseSettings.maxRecordCount = 1000
24-
backtraceDatabaseSettings.maxDatabaseSize = 10
25-
backtraceDatabaseSettings.retryInterval = 5
26-
backtraceDatabaseSettings.retryLimit = 3
27-
backtraceDatabaseSettings.retryBehaviour = RetryBehaviour.interval
28-
backtraceDatabaseSettings.retryOrder = RetryOrder.queue
25+
backtraceDatabaseSettings.maxRecordCount = 10
2926
let backtraceConfiguration = BacktraceClientConfiguration(credentials: backtraceCredentials,
3027
dbSettings: backtraceDatabaseSettings,
3128
reportsPerMin: 10,
3229
allowsAttachingDebugger: true,
3330
detectOOM: true)
3431
BacktraceClient.shared = try? BacktraceClient(configuration: backtraceConfiguration)
35-
BacktraceClient.shared?.delegate = self
3632
BacktraceClient.shared?.attributes = ["foo": "bar", "testing": true]
37-
BacktraceClient.shared?.enableBreadcrumbs()
38-
39-
let fileName = "sample.txt"
40-
guard let fileUrl = try? createAndWriteFile(fileName) else {
41-
print("Could not create the file attachment")
42-
return false
43-
}
4433
BacktraceClient.shared?.attachments.append(fileUrl)
4534

46-
BacktraceClient.shared?.loggingDestinations = [BacktraceBaseDestination(level: .debug)]
4735
do {
4836
try throwingFunc()
4937
} catch {
50-
let filePath = Bundle.main.path(forResource: "test", ofType: "txt")!
51-
BacktraceClient.shared?.send(attachmentPaths: [filePath]) { (result) in
38+
BacktraceClient.shared?.send(attachmentPaths: []) { (result) in
5239
print("AppDelegate:Result:\(result)")
5340
}
5441
}
42+
43+
44+
BacktraceClient.shared?.delegate = self
45+
BacktraceClient.shared?.loggingDestinations = [BacktraceBaseDestination(level: .debug)]
46+
47+
BacktraceClient.shared?.enableBreadcrumbs()
5548
let attributes = ["My Attribute":"My Attribute Value"]
5649
_ = BacktraceClient.shared?.addBreadcrumb("My Breadcrumb",
5750
attributes: attributes,
@@ -60,12 +53,10 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
6053
return true
6154
}
6255

63-
func createAndWriteFile(_ fileName: String) throws -> URL {
56+
static func createAndWriteFile(_ fileName: String) -> URL {
6457
let dirName = "directory"
65-
guard let libraryDirectoryUrl = try? FileManager.default.url(
66-
for: .libraryDirectory, in: .userDomainMask, appropriateFor: nil, create: true) else {
67-
throw CustomError.runtimeError
68-
}
58+
let libraryDirectoryUrl = try! FileManager.default.url(
59+
for: .libraryDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
6960
let directoryUrl = libraryDirectoryUrl.appendingPathComponent(dirName)
7061
try? FileManager().createDirectory(
7162
at: directoryUrl,
@@ -76,7 +67,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
7667
let formatter = DateFormatter()
7768
formatter.timeStyle = .medium
7869
let myData = formatter.string(from: Date())
79-
try myData.write(to: fileUrl, atomically: true, encoding: .utf8)
70+
try! myData.write(to: fileUrl, atomically: true, encoding: .utf8)
8071
return fileUrl
8172
}
8273
}

0 commit comments

Comments
 (0)