7
7
8
8
import Foundation
9
9
import JSONSafeEncoding
10
+
10
11
#if os(Linux) || os(Windows)
11
- import FoundationNetworking
12
+ import FoundationNetworking
12
13
#endif
13
14
14
15
// MARK: - Custom AnonymousId generator
@@ -29,7 +30,8 @@ public enum OperatingMode {
29
30
/// The operation of the Analytics client are asynchronous.
30
31
case asynchronous
31
32
32
- static internal let defaultQueue = DispatchQueue ( label: " com.segment.operatingModeQueue " , qos: . utility)
33
+ static internal let defaultQueue = DispatchQueue (
34
+ label: " com.segment.operatingModeQueue " , qos: . utility)
33
35
}
34
36
35
37
// MARK: - Storage Mode
@@ -47,7 +49,6 @@ public enum StorageMode {
47
49
48
50
// MARK: - Internal Configuration
49
51
50
- @objc ( SEGTrackedLifecycleEvent)
51
52
public final class TrackedLifecycleEvent : NSObject , OptionSet {
52
53
public let rawValue : Int
53
54
@@ -63,44 +64,44 @@ public final class TrackedLifecycleEvent: NSObject, OptionSet {
63
64
rawValue. hashValue
64
65
}
65
66
66
- @ objc public static let none : TrackedLifecycleEvent = [ ]
67
- @ objc public static let applicationInstalled = TrackedLifecycleEvent ( rawValue: 1 << 0 )
68
- @ objc public static let applicationUpdated = TrackedLifecycleEvent ( rawValue: 1 << 1 )
69
- @ objc public static let applicationOpened = TrackedLifecycleEvent ( rawValue: 1 << 2 )
70
- @ objc public static let applicationBackgrounded = TrackedLifecycleEvent ( rawValue: 1 << 3 )
71
- @ objc public static let applicationForegrounded = TrackedLifecycleEvent ( rawValue: 1 << 4 )
67
+ public static let none : TrackedLifecycleEvent = [ ]
68
+ public static let applicationInstalled = TrackedLifecycleEvent ( rawValue: 1 << 0 )
69
+ public static let applicationUpdated = TrackedLifecycleEvent ( rawValue: 1 << 1 )
70
+ public static let applicationOpened = TrackedLifecycleEvent ( rawValue: 1 << 2 )
71
+ public static let applicationBackgrounded = TrackedLifecycleEvent ( rawValue: 1 << 3 )
72
+ public static let applicationForegrounded = TrackedLifecycleEvent ( rawValue: 1 << 4 )
72
73
#if os(macOS)
73
- @ objc public static let applicationUnhidden = TrackedLifecycleEvent ( rawValue: 1 << 5 )
74
- @ objc public static let applicationHidden = TrackedLifecycleEvent ( rawValue: 1 << 6 )
75
- @ objc public static let applicationTerminated = TrackedLifecycleEvent ( rawValue: 1 << 7 )
76
-
77
- @ objc public static let all : TrackedLifecycleEvent = [
78
- . applicationInstalled,
79
- . applicationUpdated,
80
- . applicationOpened,
81
- . applicationBackgrounded,
82
- . applicationForegrounded,
83
- . applicationUnhidden,
84
- . applicationHidden,
85
- . applicationTerminated,
86
- ]
74
+ public static let applicationUnhidden = TrackedLifecycleEvent ( rawValue: 1 << 5 )
75
+ public static let applicationHidden = TrackedLifecycleEvent ( rawValue: 1 << 6 )
76
+ public static let applicationTerminated = TrackedLifecycleEvent ( rawValue: 1 << 7 )
77
+
78
+ public static let all : TrackedLifecycleEvent = [
79
+ . applicationInstalled,
80
+ . applicationUpdated,
81
+ . applicationOpened,
82
+ . applicationBackgrounded,
83
+ . applicationForegrounded,
84
+ . applicationUnhidden,
85
+ . applicationHidden,
86
+ . applicationTerminated,
87
+ ]
87
88
#elseif os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
88
- @ objc public static let all : TrackedLifecycleEvent = [
89
- . applicationInstalled,
90
- . applicationUpdated,
91
- . applicationOpened,
92
- . applicationBackgrounded,
93
- . applicationForegrounded,
94
- ]
89
+ public static let all : TrackedLifecycleEvent = [
90
+ . applicationInstalled,
91
+ . applicationUpdated,
92
+ . applicationOpened,
93
+ . applicationBackgrounded,
94
+ . applicationForegrounded,
95
+ ]
95
96
#elseif os(watchOS)
96
- @ objc public static let all : TrackedLifecycleEvent = [
97
- . applicationInstalled,
98
- . applicationUpdated,
99
- . applicationOpened,
100
- . applicationBackgrounded,
101
- ]
97
+ public static let all : TrackedLifecycleEvent = [
98
+ . applicationInstalled,
99
+ . applicationUpdated,
100
+ . applicationOpened,
101
+ . applicationBackgrounded,
102
+ ]
102
103
#else
103
- @ objc public static let all = TrackedLifecycleEvent . none
104
+ public static let all = TrackedLifecycleEvent . none
104
105
#endif
105
106
}
106
107
@@ -121,7 +122,8 @@ public class Configuration {
121
122
var operatingMode : OperatingMode = . asynchronous
122
123
var flushQueue : DispatchQueue = OperatingMode . defaultQueue
123
124
var userAgent : String ? = nil
124
- var jsonNonConformingNumberStrategy : JSONSafeEncoder . NonConformingFloatEncodingStrategy = . zero
125
+ var jsonNonConformingNumberStrategy : JSONSafeEncoder . NonConformingFloatEncodingStrategy =
126
+ . zero
125
127
var storageMode : StorageMode = . disk
126
128
var anonymousIdGenerator : AnonymousIdGenerator = SegmentAnonymousId ( )
127
129
var httpSession : ( ( ) -> any HTTPSession ) = HTTPSessions . urlSession
@@ -145,10 +147,9 @@ public class Configuration {
145
147
}
146
148
}
147
149
148
-
149
150
// MARK: - Analytics Configuration
150
151
151
- public extension Configuration {
152
+ extension Configuration {
152
153
153
154
/// Sets a reference to your application. This can be useful in instances
154
155
/// where referring back to your application is necessary, such as within plugins
@@ -157,7 +158,7 @@ public extension Configuration {
157
158
/// - Parameter value: A reference to your application.
158
159
/// - Returns: The current Configuration.
159
160
@discardableResult
160
- func application( _ value: Any ? ) -> Configuration {
161
+ public func application( _ value: Any ? ) -> Configuration {
161
162
values. application = value
162
163
return self
163
164
}
@@ -167,8 +168,11 @@ public extension Configuration {
167
168
/// - Parameter enabled: A bool value
168
169
/// - Returns: The current Configuration.
169
170
@discardableResult
170
- @available ( * , deprecated, message: " Use `setTrackedApplicationLifecycleEvents(_:)` for more granular control " )
171
- func trackApplicationLifecycleEvents( _ enabled: Bool ) -> Configuration {
171
+ @available (
172
+ * , deprecated,
173
+ message: " Use `setTrackedApplicationLifecycleEvents(_:)` for more granular control "
174
+ )
175
+ public func trackApplicationLifecycleEvents( _ enabled: Bool ) -> Configuration {
172
176
values. trackedApplicationLifecycleEvents = enabled ? . all : . none
173
177
return self
174
178
}
@@ -178,7 +182,9 @@ public extension Configuration {
178
182
/// - Parameter events: An option set of the events to track.
179
183
/// - Returns: The current Configuration.
180
184
@discardableResult
181
- func setTrackedApplicationLifecycleEvents( _ events: TrackedLifecycleEvent ) -> Configuration {
185
+ public func setTrackedApplicationLifecycleEvents( _ events: TrackedLifecycleEvent )
186
+ -> Configuration
187
+ {
182
188
values. trackedApplicationLifecycleEvents = events
183
189
return self
184
190
}
@@ -189,7 +195,7 @@ public extension Configuration {
189
195
/// - Parameter count: Event count to trigger a flush.
190
196
/// - Returns: The current Configuration.
191
197
@discardableResult
192
- func flushAt( _ count: Int ) -> Configuration {
198
+ public func flushAt( _ count: Int ) -> Configuration {
193
199
values. flushAt = count
194
200
return self
195
201
}
@@ -200,7 +206,7 @@ public extension Configuration {
200
206
/// - Parameter interval: A time interval
201
207
/// - Returns: The current Configuration.
202
208
@discardableResult
203
- func flushInterval( _ interval: TimeInterval ) -> Configuration {
209
+ public func flushInterval( _ interval: TimeInterval ) -> Configuration {
204
210
values. flushInterval = interval
205
211
return self
206
212
}
@@ -224,7 +230,7 @@ public extension Configuration {
224
230
/// - Parameter settings:
225
231
/// - Returns: The current Configuration.
226
232
@discardableResult
227
- func defaultSettings( _ settings: Settings ? ) -> Configuration {
233
+ public func defaultSettings( _ settings: Settings ? ) -> Configuration {
228
234
values. defaultSettings = settings
229
235
return self
230
236
}
@@ -236,7 +242,7 @@ public extension Configuration {
236
242
/// - Parameter value: true/false
237
243
/// - Returns: The current Configuration.
238
244
@discardableResult
239
- func autoAddSegmentDestination( _ value: Bool ) -> Configuration {
245
+ public func autoAddSegmentDestination( _ value: Bool ) -> Configuration {
240
246
values. autoAddSegmentDestination = value
241
247
return self
242
248
}
@@ -248,7 +254,7 @@ public extension Configuration {
248
254
/// - Parameter value: A string representing the desired API host.
249
255
/// - Returns: The current Configuration.
250
256
@discardableResult
251
- func apiHost( _ value: String ) -> Configuration {
257
+ public func apiHost( _ value: String ) -> Configuration {
252
258
values. apiHost = value
253
259
return self
254
260
}
@@ -260,7 +266,7 @@ public extension Configuration {
260
266
/// - Parameter value: A string representing the desired CDN host.
261
267
/// - Returns: The current Configuration.
262
268
@discardableResult
263
- func cdnHost( _ value: String ) -> Configuration {
269
+ public func cdnHost( _ value: String ) -> Configuration {
264
270
values. cdnHost = value
265
271
return self
266
272
}
@@ -271,7 +277,7 @@ public extension Configuration {
271
277
/// - Parameter value: A block to call when requests are made.
272
278
/// - Returns: The current Configuration.
273
279
@discardableResult
274
- func requestFactory( _ value: @escaping ( URLRequest ) -> URLRequest ) -> Configuration {
280
+ public func requestFactory( _ value: @escaping ( URLRequest ) -> URLRequest ) -> Configuration {
275
281
values. requestFactory = value
276
282
return self
277
283
}
@@ -283,13 +289,13 @@ public extension Configuration {
283
289
/// - Parameter value: A block to be called when an error occurs.
284
290
/// - Returns: The current Configuration.
285
291
@discardableResult
286
- func errorHandler( _ value: @escaping ( Error ) -> Void ) -> Configuration {
292
+ public func errorHandler( _ value: @escaping ( Error ) -> Void ) -> Configuration {
287
293
values. errorHandler = value
288
294
return self
289
295
}
290
296
291
297
@discardableResult
292
- func flushPolicies( _ policies: [ FlushPolicy ] ) -> Configuration {
298
+ public func flushPolicies( _ policies: [ FlushPolicy ] ) -> Configuration {
293
299
values. flushPolicies = policies
294
300
return self
295
301
}
@@ -299,55 +305,59 @@ public extension Configuration {
299
305
/// is desired. Use `.client` when operating in a long lived process,
300
306
/// desktop/mobile application.
301
307
@discardableResult
302
- func operatingMode( _ mode: OperatingMode ) -> Configuration {
308
+ public func operatingMode( _ mode: OperatingMode ) -> Configuration {
303
309
values. operatingMode = mode
304
310
return self
305
311
}
306
312
307
313
/// Specify a custom queue to use when performing a flush operation. The default
308
314
/// value is a Segment owned background queue.
309
315
@discardableResult
310
- func flushQueue( _ queue: DispatchQueue ) -> Configuration {
316
+ public func flushQueue( _ queue: DispatchQueue ) -> Configuration {
311
317
values. flushQueue = queue
312
318
return self
313
319
}
314
320
315
321
/// Specify a custom UserAgent string. This bypasses the OS dependent check entirely.
316
322
@discardableResult
317
- func userAgent( _ userAgent: String ) -> Configuration {
323
+ public func userAgent( _ userAgent: String ) -> Configuration {
318
324
values. userAgent = userAgent
319
325
return self
320
326
}
321
327
322
328
/// This option specifies how NaN/Infinity are handled when encoding JSON.
323
329
/// The default is .zero. See JSONSafeEncoder.NonConformingFloatEncodingStrategy for more informatino.
324
330
@discardableResult
325
- func jsonNonConformingNumberStrategy( _ strategy: JSONSafeEncoder . NonConformingFloatEncodingStrategy ) -> Configuration {
331
+ public func jsonNonConformingNumberStrategy(
332
+ _ strategy: JSONSafeEncoder . NonConformingFloatEncodingStrategy
333
+ ) -> Configuration {
326
334
values. jsonNonConformingNumberStrategy = strategy
327
335
JSON . jsonNonConformingNumberStrategy = values. jsonNonConformingNumberStrategy
328
336
return self
329
337
}
330
-
338
+
331
339
/// Specify the storage mode to use. The default is `.disk`.
332
340
@discardableResult
333
- func storageMode( _ mode: StorageMode ) -> Configuration {
341
+ public func storageMode( _ mode: StorageMode ) -> Configuration {
334
342
values. storageMode = mode
335
343
return self
336
344
}
337
-
345
+
338
346
/// Specify a custom anonymousId generator. The default is and instance of `SegmentAnonymousId`.
339
347
@discardableResult
340
- func anonymousIdGenerator( _ generator: AnonymousIdGenerator ) -> Configuration {
348
+ public func anonymousIdGenerator( _ generator: AnonymousIdGenerator ) -> Configuration {
341
349
values. anonymousIdGenerator = generator
342
350
return self
343
351
}
344
-
352
+
345
353
/// Use a custom HTTP session; Useful for non-apple platforms where Swift networking isn't as mature
346
354
/// or has issues to work around.
347
355
/// - Parameter httpSession: A class conforming to the HTTPSession protocol
348
356
/// - Returns: The current configuration
349
357
@discardableResult
350
- func httpSession( _ httpSession: @escaping @autoclosure ( ) -> any HTTPSession ) -> Configuration {
358
+ public func httpSession( _ httpSession: @escaping @autoclosure ( ) -> any HTTPSession )
359
+ -> Configuration
360
+ {
351
361
values. httpSession = httpSession
352
362
return self
353
363
}
0 commit comments