Skip to content

Commit 5a23d43

Browse files
authored
Merge pull request #117 from smartmobilefactory/update-sentry-appcenter
update Sentry to `6.1.3` and AppCenter to `4.1.0`
2 parents 4fd42a9 + 7405ab7 commit 5a23d43

3 files changed

Lines changed: 41 additions & 49 deletions

File tree

AppCenter/AppCenterSDK+HiDrive.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AppCenterSDK: NSObject {
4141
// MARK: - Public properties
4242

4343
static var wasInitialized : Bool {
44-
return MSAppCenter.isConfigured()
44+
return AppCenter.isConfigured
4545
}
4646

4747
// MARK: - Methods
@@ -62,27 +62,27 @@ class AppCenterSDK: NSObject {
6262

6363
#if !os(macOS)
6464
if (configuration.isDistributionEnabled == true) {
65-
services.append(MSDistribute.self)
65+
services.append(Distribute.self)
6666
}
6767
#endif
6868

6969
if (configuration.isCrashReportEnabled == true) {
70-
services.append(MSCrashes.self)
70+
services.append(Crashes.self)
7171
}
7272

7373
guard (services.isEmpty == false) else {
7474
return
7575
}
7676

77-
MSAppCenter.start(configuration.appSecret, withServices: services)
78-
MSCrashes.setEnabled(configuration.isCrashReportEnabled)
79-
MSCrashes.setDelegate(self.delegate)
77+
AppCenter.start(withAppSecret: configuration.appSecret, services: services)
78+
Crashes.enabled = configuration.isCrashReportEnabled
79+
Crashes.delegate = self.delegate
8080
}
8181

8282
#if !os(macOS)
8383
/// Returns True, if and only if the Service got started and is enabled.
8484
static var isDistributionEnabled: Bool {
85-
return MSDistribute.isEnabled()
85+
return Distribute.enabled
8686
}
8787

8888
/// Will enable or disable the Distribution Feature of AppCenter
@@ -96,13 +96,13 @@ class AppCenterSDK: NSObject {
9696
///
9797
/// - Parameter enabled: Enable or Disable Distribtion
9898
static func enableDistribution(enabled: Bool = true) {
99-
MSDistribute.setEnabled(enabled)
99+
Distribute.enabled = enabled
100100
}
101101
#endif
102102

103103
/// Returns True, if and only if Crash Reporting is enabled.
104104
static var isCrashReportingEnabled: Bool {
105-
return MSCrashes.isEnabled()
105+
return Crashes.enabled
106106
}
107107

108108
/// Will enable or disable the sending od crash reports to AppCenter
@@ -116,13 +116,13 @@ class AppCenterSDK: NSObject {
116116
///
117117
/// - Parameter enabled: Enable or Disable Distribtion
118118
static func enableCrashReporting(enabled: Bool = true) {
119-
MSCrashes.setEnabled(enabled)
119+
Crashes.enabled = enabled
120120
}
121121

122122
/// This will create a `fatalError` to crash the app.
123123
static func performTestCrash() {
124124

125-
MSCrashes.generateTestCrash()
125+
Crashes.generateTestCrash()
126126
}
127127
}
128128

@@ -172,20 +172,20 @@ extension AppCenterSDK {
172172
}
173173
}
174174

175-
private class AppCenterSDKDelegate : NSObject, MSCrashesDelegate {
175+
private class AppCenterSDKDelegate : NSObject, CrashesDelegate {
176176

177177
private var isLogUploadEnabled : Bool
178178

179179
init(isLogUploadEnabled : Bool) {
180180
self.isLogUploadEnabled = isLogUploadEnabled
181181
}
182182

183-
func attachments(with crashes: MSCrashes!, for errorReport: MSErrorReport!) -> [MSErrorAttachmentLog]! {
183+
func attachments(with crashes: Crashes, for errorReport: ErrorReport) -> [ErrorAttachmentLog]? {
184184
guard (self.isLogUploadEnabled == true) else {
185185
return []
186186
}
187187

188-
return [MSErrorAttachmentLog.attachment(withText: self.applicationLog, filename: AppCenterConstants.crashLogFileName)]
188+
return [ErrorAttachmentLog.attachment(withText: self.applicationLog, filename: AppCenterConstants.crashLogFileName)]
189189
}
190190

191191
private var applicationLog: String {

AppCenter/AppCenterSDK+SMFLogger.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AppCenterSDK: NSObject {
3030
// MARK: - Public properties
3131

3232
static var wasInitialized : Bool {
33-
return MSAppCenter.isConfigured()
33+
return AppCenter.isConfigured
3434
}
3535

3636
// MARK: - Methods
@@ -45,14 +45,14 @@ class AppCenterSDK: NSObject {
4545
return
4646
}
4747

48-
let services = (configuration.isDistributionEnabled == true) ? [MSDistribute.self] : []
48+
let services = (configuration.isDistributionEnabled == true) ? [Distribute.self] : []
4949

50-
MSAppCenter.start(configuration.appSecret, withServices: services)
50+
AppCenter.start(withAppSecret: configuration.appSecret, services: services)
5151
}
5252

5353
/// Returns True, if and only if the Service got started and is enabled.
5454
static var isDistributionEnabled: Bool {
55-
return MSDistribute.isEnabled()
55+
return Distribute.enabled
5656
}
5757

5858
/// Will enable or disable the Distribution Feature of AppCenter
@@ -66,7 +66,7 @@ class AppCenterSDK: NSObject {
6666
///
6767
/// - Parameter enabled: Enable or Disable Distribtion
6868
static func enableDistribution(enabled: Bool = true) {
69-
MSDistribute.setEnabled(enabled)
69+
Distribute.enabled = enabled
7070
}
7171
}
7272

Sentry/SentrySDK+SMFLogger.swift

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ fileprivate struct SentryConstants {
1414
static let smfLogUploadMaxSizeDefault = 5000
1515
}
1616

17-
class SentrySDK: NSObject {
17+
class SMFSentrySDK: NSObject {
1818

1919
// MARK: - Private static properties
2020

21-
fileprivate static var shared : SentrySDK?
21+
fileprivate static var shared : SMFSentrySDK?
2222

2323
fileprivate static let isDebugBuild : Bool = {
2424
#if DEBUG
@@ -36,15 +36,15 @@ class SentrySDK: NSObject {
3636
// MARK: - Public properties
3737

3838
static var wasInitialized : Bool {
39-
return (SentrySDK.shared?.isInitialized ?? false)
39+
return (SMFSentrySDK.shared?.isInitialized ?? false)
4040
}
4141

4242
// MARK: - Initialization
4343

4444
override init() {
4545
super.init()
4646

47-
SentrySDK.shared = self
47+
SMFSentrySDK.shared = self
4848
}
4949

5050
// MARK: - Methods
@@ -53,38 +53,30 @@ class SentrySDK: NSObject {
5353
///
5454
/// - Parameters:
5555
/// - configuration: Configuration object
56-
static func setup(configuration: SentrySDK.Configuration) {
56+
static func setup(configuration: SMFSentrySDK.Configuration) {
5757
guard (self.isDebugBuild == false || configuration.enableDebug == true) else {
5858
return
5959
}
6060

61-
let instance = (self.shared ?? SentrySDK())
62-
63-
do {
64-
Client.shared = try Client(dsn: configuration.sentryDSN)
65-
Client.shared?.beforeSerializeEvent = { (event: Event) in
66-
event.environment = SentrySDK.Configuration.environment
61+
let instance = (self.shared ?? SMFSentrySDK())
6762

63+
SentrySDK.start { (options: Options) in
64+
options.dsn = configuration.sentryDSN
65+
options.debug = configuration.enableDebug
66+
options.beforeBreadcrumb = { (event: Breadcrumb?) in
6867
if
69-
(event.level != .debug),
68+
(event?.level != .debug),
7069
(configuration.enableSMFLogUpload == true),
7170
let loggerContents = Logger.logFilesContent(maxSize: configuration.smfLogUploadMaxSize) {
72-
event.message = loggerContents
71+
event?.message = loggerContents
7372
}
74-
}
7573

76-
if (configuration.enableBreadcrumbs == true) {
77-
Client.shared?.enableAutomaticBreadcrumbTracking()
74+
return event
7875
}
79-
80-
try Client.shared?.startCrashHandler()
81-
82-
instance.configuration = configuration
83-
84-
instance.isInitialized = true
85-
} catch let error {
86-
Log.Channel.Manager.sentry.error("Error initialising sentry: \(error.localizedDescription)")
8776
}
77+
78+
instance.configuration = configuration
79+
instance.isInitialized = true
8880
}
8981

9082
/// This will create a `fatalError` to crash the app.
@@ -95,7 +87,7 @@ class SentrySDK: NSObject {
9587
return
9688
}
9789

98-
Client.shared?.reportUserException("TestCrash", reason: "Only testing crashes", language: "swift", lineOfCode: "23", stackTrace: [], logAllThreads: false, terminateProgram: true)
90+
SentrySDK.crash()
9991
fatalError("This is a test crash to trigger a crash report in Sentry Dashboard")
10092
}
10193

@@ -107,7 +99,7 @@ class SentrySDK: NSObject {
10799
/// - additionalData : dictionary of key/value pairs that will apear under Additional Data in Sentry
108100
/// - includeLoggerData : if the event should also include the last part of SMFLogger
109101
/// - smfLogUploadMaxSize : The max count of characters which should be uploaded
110-
static func sendEvent(title: String, message: String, additionalData: [String: Any]? = nil, includeLoggerData: Bool = true, smfLogUploadMaxSize: Int = (SentrySDK.shared?.configuration?.smfLogUploadMaxSize ?? SentryConstants.smfLogUploadMaxSizeDefault)) {
102+
static func sendEvent(title: String, message: String, additionalData: [String: Any]? = nil, includeLoggerData: Bool = true, smfLogUploadMaxSize: Int = (SMFSentrySDK.shared?.configuration?.smfLogUploadMaxSize ?? SentryConstants.smfLogUploadMaxSizeDefault)) {
111103
let event = Event(level: .debug)
112104

113105
if (additionalData != nil) {
@@ -123,13 +115,13 @@ class SentrySDK: NSObject {
123115
fullMessage.append(loggerContents)
124116
}
125117

126-
event.message = fullMessage
118+
event.message = SentryMessage(formatted: fullMessage)
127119

128-
Client.shared?.send(event: event, completion: nil)
120+
SentrySDK.capture(event: event)
129121
}
130122
}
131123

132-
extension SentrySDK {
124+
extension SMFSentrySDK {
133125

134126
struct Configuration {
135127

@@ -177,7 +169,7 @@ extension SentrySDK {
177169
self.smfLogUploadMaxSize = smfLogUploadMaxSize
178170
}
179171

180-
static var `default`: SentrySDK.Configuration {
172+
static var `default`: SMFSentrySDK.Configuration {
181173
return Configuration()
182174
}
183175
}

0 commit comments

Comments
 (0)