@@ -10,10 +10,13 @@ import Foundation
1010import AppCenter
1111import AppCenterCrashes
1212import AppCenterDistribute
13+ import SMFLogger
14+
1315
1416fileprivate enum AppCenterConstants {
1517
1618 static let appSecretKey = " AppCenterAppSecret "
19+ static let smfLogUploadMaxSize : Int = 5000
1720}
1821
1922class AppCenterSDK : NSObject {
@@ -30,6 +33,7 @@ class AppCenterSDK: NSObject {
3033
3134 // MARK: - Private properties
3235
36+ fileprivate static var shared : AppCenterSDK ?
3337 fileprivate var isInitialized = false
3438 fileprivate var configuration : Configuration ?
3539
@@ -54,7 +58,8 @@ class AppCenterSDK: NSObject {
5458 let services = ( configuration. isDistributionEnabled == true ) ? [ MSCrashes . self, MSDistribute . self] : [ MSCrashes . self]
5559
5660 MSAppCenter . start ( configuration. appSecret, withServices: services)
57- MSCrashes . setEnabled ( HDManager . shared. settings. crashReportsEnabled)
61+ MSCrashes . setEnabled ( configuration. enableCrashes)
62+ MSCrashes . setDelegate ( shared)
5863 }
5964
6065 /// Returns True, if and only if the Service got started and is enabled.
@@ -92,14 +97,15 @@ extension AppCenterSDK {
9297 fileprivate var enableDebug : Bool
9398 fileprivate var appSecret : String
9499 fileprivate var isDistributionEnabled : Bool
100+ fileprivate var enableCrashes : Bool
95101
96102 /// Initializes a AppCenterSDK Configuration
97103 ///
98104 /// - Parameters:
99105 /// - appSecret: supply this manually if you dont want it in the info.plist
100106 /// - enableDebug: Should start the Services even for Debug, Default is false
101107 /// - isDistributionEnabled: Should start the Distribution Service, Default is false for Debug and Live apps, else true,
102- init ( appSecret: String ? = nil , enableDebug: Bool = false , isDistributionEnabled: Bool ? = nil ) {
108+ init ( appSecret: String ? = nil , enableDebug: Bool = false , isDistributionEnabled: Bool ? = nil , enableCrashes : Bool = true ) {
103109
104110 let appSecretFromBundle = Bundle . main. object ( forInfoDictionaryKey: AppCenterConstants . appSecretKey) as? String
105111
@@ -109,6 +115,7 @@ extension AppCenterSDK {
109115
110116 self . enableDebug = enableDebug
111117 self . appSecret = _appSecret
118+ self . enableCrashes = enableCrashes
112119
113120 #if DEBUG
114121 self . isDistributionEnabled = isDistributionEnabled ?? false
@@ -124,3 +131,17 @@ extension AppCenterSDK {
124131 }
125132 }
126133}
134+
135+ extension AppCenterSDK : MSCrashesDelegate {
136+
137+ private func applicationLog( ) -> String ? {
138+ guard
139+ let description = Logger . logFilesContent ( maxSize: AppCenterConstants . smfLogUploadMaxSize) ,
140+ ( description. isEmpty == false ) else {
141+ return nil
142+ }
143+
144+ return description
145+ }
146+ }
147+
0 commit comments