Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Simple Crashlytics Service (#522)
Browse files Browse the repository at this point in the history
* implemented simple `CrashlyticsService`

* replaced existing crashlytics usage
  • Loading branch information
Antonwy authored Jan 28, 2023
1 parent edcc7cc commit 76ffecc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
12 changes: 12 additions & 0 deletions Campus-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
97997AE7277234120079F809 /* XMLCoder in Frameworks */ = {isa = PBXBuildFile; productRef = 97997AE6277234120079F809 /* XMLCoder */; };
97C9AB1227732A200097B10C /* SwiftUICharts in Frameworks */ = {isa = PBXBuildFile; productRef = 97C9AB1127732A200097B10C /* SwiftUICharts */; };
97F8A79327E641570099EE83 /* AcademicDegree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97F8A79227E641570099EE83 /* AcademicDegree.swift */; };
99706870298569E10028D235 /* CrashlyticsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9970686F298569E10028D235 /* CrashlyticsService.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -517,6 +518,7 @@
97270F5927AB2A4900BB25E4 /* Array+Rearrange.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Array+Rearrange.swift"; sourceTree = "<group>"; };
974D5B9927E5E9CB00FD7B11 /* GlowBorder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlowBorder.swift; sourceTree = "<group>"; };
97F8A79227E641570099EE83 /* AcademicDegree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AcademicDegree.swift; sourceTree = "<group>"; };
9970686F298569E10028D235 /* CrashlyticsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrashlyticsService.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -1083,6 +1085,7 @@
366F0E8227580CFB0091651D /* Campus-iOS */ = {
isa = PBXGroup;
children = (
9970686E298569CE0028D235 /* Crashlytics */,
085DE9C428AB7C3D0045095F /* AnalyticsComponent */,
3654F3692851710E008AD5DC /* RoomFinder */,
36BB6F8027B39B2200F224AB /* LectureSearchComponent */,
Expand Down Expand Up @@ -1514,6 +1517,14 @@
path = Icons;
sourceTree = "<group>";
};
9970686E298569CE0028D235 /* Crashlytics */ = {
isa = PBXGroup;
children = (
9970686F298569E10028D235 /* CrashlyticsService.swift */,
);
path = Crashlytics;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -1843,6 +1854,7 @@
3654F38A28518640008AD5DC /* StudyRoomDetailsView.swift in Sources */,
36AF61ED27A2FD7800FEBD98 /* FailedView.swift in Sources */,
36108BBE27A3046B007DC62D /* LecturesService.swift in Sources */,
99706870298569E10028D235 /* CrashlyticsService.swift in Sources */,
36108BF027A304B6007DC62D /* PanelContentView.swift in Sources */,
36AF61F127A2FD7800FEBD98 /* XMLSerializer.swift in Sources */,
08FAFD1A288DED6F006A0E27 /* WidgetRecommender.swift in Sources */,
Expand Down
12 changes: 3 additions & 9 deletions Campus-iOS/Base/Entity/EntityImporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,15 @@ final class Importer<EntityType: Entity, EntityContainer: Decodable, DecoderType
let storage = try decoder.decode(EntityContainer.self, from: data)
handler?(.success(storage))
} catch let apiError as APIError {
#if !DEBUG
Crashlytics.crashlytics().record(error: apiError)
#endif
CrashlyticsService.log(apiError)
handler?(.failure(apiError))
return
} catch let decodingError as DecodingError {
#if !DEBUG
Crashlytics.crashlytics().record(error: decodingError)
#endif
CrashlyticsService.log(decodingError)
handler?(.failure(decodingError))
return
} catch let error {
#if !DEBUG
Crashlytics.crashlytics().record(error: error)
#endif
CrashlyticsService.log(error)
handler?(.failure(error))
}
}
Expand Down
4 changes: 1 addition & 3 deletions Campus-iOS/Base/Networking/APIResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ struct TUMOnlineAPIResponse<T: Decodable>: Decodable {
return try $0.result.get()
}
catch {
#if !DEBUG
Crashlytics.crashlytics().record(error: error)
#endif
CrashlyticsService.log(error)
return nil
}
}
Expand Down
25 changes: 25 additions & 0 deletions Campus-iOS/Crashlytics/CrashlyticsService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// CrashlyticsService.swift
// Campus-iOS
//
// Created by Anton Wyrowski on 28.01.23.
//

import Foundation
import FirebaseCrashlytics

class CrashlyticsService {
static private let crashlytics = Crashlytics.crashlytics()

static func log(_ error: Error) -> Void {
#if !DEBUG
CrashlyticsService.crashlytics.record(error: error)
#endif
}

static func log(_ value: String) -> Void {
#if !DEBUG
CrashlyticsService.crashlytics.log(value)
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ final class AuthenticationHandler: RequestAdapter, RequestRetrier {
let encodedRequest = try URLEncoding.default.encode(urlRequest, with: ["pToken": pToken])
return completion(.success(encodedRequest))
} catch let error {
#if !DEBUG
Crashlytics.crashlytics().record(error: error)
#endif
CrashlyticsService.log(error)
return completion(.failure(error))
}
case urlString where TUMCabeAPI.requiresAuth.contains { urlString.contains($0)}:
Expand Down

0 comments on commit 76ffecc

Please sign in to comment.