@@ -11,7 +11,9 @@ func throwingFunc() throws {
11
11
12
12
@UIApplicationMain
13
13
final class AppDelegate : UIResponder , UIApplicationDelegate {
14
-
14
+
15
+ let fileUrl = createAndWriteFile ( " sample.txt " )
16
+
15
17
var window : UIWindow ?
16
18
17
19
func application( _ application: UIApplication ,
@@ -20,38 +22,29 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
20
22
token: Keys . backtraceToken as String )
21
23
22
24
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
29
26
let backtraceConfiguration = BacktraceClientConfiguration ( credentials: backtraceCredentials,
30
27
dbSettings: backtraceDatabaseSettings,
31
28
reportsPerMin: 10 ,
32
29
allowsAttachingDebugger: true ,
33
30
detectOOM: true )
34
31
BacktraceClient . shared = try ? BacktraceClient ( configuration: backtraceConfiguration)
35
- BacktraceClient . shared? . delegate = self
36
32
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
- }
44
33
BacktraceClient . shared? . attachments. append ( fileUrl)
45
34
46
- BacktraceClient . shared? . loggingDestinations = [ BacktraceBaseDestination ( level: . debug) ]
47
35
do {
48
36
try throwingFunc ( )
49
37
} 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
52
39
print ( " AppDelegate:Result: \( result) " )
53
40
}
54
41
}
42
+
43
+
44
+ BacktraceClient . shared? . delegate = self
45
+ BacktraceClient . shared? . loggingDestinations = [ BacktraceBaseDestination ( level: . debug) ]
46
+
47
+ BacktraceClient . shared? . enableBreadcrumbs ( )
55
48
let attributes = [ " My Attribute " : " My Attribute Value " ]
56
49
_ = BacktraceClient . shared? . addBreadcrumb ( " My Breadcrumb " ,
57
50
attributes: attributes,
@@ -60,12 +53,10 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
60
53
return true
61
54
}
62
55
63
- func createAndWriteFile( _ fileName: String ) throws -> URL {
56
+ static func createAndWriteFile( _ fileName: String ) -> URL {
64
57
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 )
69
60
let directoryUrl = libraryDirectoryUrl. appendingPathComponent ( dirName)
70
61
try ? FileManager ( ) . createDirectory (
71
62
at: directoryUrl,
@@ -76,7 +67,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {
76
67
let formatter = DateFormatter ( )
77
68
formatter. timeStyle = . medium
78
69
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)
80
71
return fileUrl
81
72
}
82
73
}
0 commit comments