@@ -11,7 +11,9 @@ func throwingFunc() throws {
1111
1212@UIApplicationMain
1313final 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