mirror of
https://github.com/aptabase/aptabase-swift.git
synced 2026-01-18 22:21:17 +01:00
feat: allow setting debug/release explicitly from options
This commit is contained in:
@@ -4,7 +4,11 @@ import Aptabase
|
||||
@main
|
||||
struct HelloWorldMacApp: App {
|
||||
init() {
|
||||
Aptabase.shared.initialize(appKey: "A-DEV-0000000000");
|
||||
Aptabase.shared.initialize(
|
||||
appKey: "A-DEV-0000000000",
|
||||
// optionally track events as release, avoiding the default environment variable
|
||||
options: InitOptions(trackingMode: .asRelease)
|
||||
)
|
||||
}
|
||||
|
||||
var body: some Scene {
|
||||
|
||||
@@ -33,6 +33,10 @@ public class Aptabase: NSObject {
|
||||
return
|
||||
}
|
||||
|
||||
if let trackingMode = options?.trackingMode, trackingMode != .readFromEnvironment {
|
||||
env.isDebug = trackingMode.isDebug
|
||||
}
|
||||
|
||||
client = AptabaseClient(appKey: appKey, baseUrl: baseUrl, env: env, options: options)
|
||||
|
||||
let notifications = NotificationCenter.default
|
||||
|
||||
@@ -4,12 +4,15 @@ import Foundation
|
||||
public final class InitOptions: NSObject {
|
||||
let host: String?
|
||||
let flushInterval: Double?
|
||||
let trackingMode: TrackingMode
|
||||
|
||||
/// - Parameters:
|
||||
/// - host: The custom host to use. If none provided will use Aptabase's servers.
|
||||
/// - flushInterval: Defines a custom interval for flushing events.
|
||||
@objc public init(host: String? = nil, flushInterval: NSNumber? = nil) {
|
||||
/// - trackingMode: Use TrackingMode.asDebug for debug events, TrackingMode.asRelease for release events, or TrackingMode.readFromEnvironment to use the environment setting. Defaults to .readFromEnvironment if omitted.
|
||||
@objc public init(host: String? = nil, flushInterval: NSNumber? = nil, trackingMode: TrackingMode = .readFromEnvironment) {
|
||||
self.host = host
|
||||
self.flushInterval = flushInterval?.doubleValue
|
||||
self.trackingMode = trackingMode
|
||||
}
|
||||
}
|
||||
|
||||
26
Sources/Aptabase/TrackingMode.swift
Normal file
26
Sources/Aptabase/TrackingMode.swift
Normal file
@@ -0,0 +1,26 @@
|
||||
import Foundation
|
||||
|
||||
/// Represents the tracking mode (release/debug) for the client.
|
||||
@objc public class TrackingMode: NSObject {
|
||||
@objc public static let asDebug = TrackingMode(rawValue: 0)
|
||||
@objc public static let asRelease = TrackingMode(rawValue: 1)
|
||||
@objc public static let readFromEnvironment = TrackingMode(rawValue: 2)
|
||||
|
||||
private let rawValue: Int
|
||||
|
||||
private init(rawValue: Int) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
|
||||
@objc public var isDebug: Bool {
|
||||
return self.rawValue == 0
|
||||
}
|
||||
|
||||
@objc public var isRelease: Bool {
|
||||
return self.rawValue == 1
|
||||
}
|
||||
|
||||
@objc public var isReadFromEnvironment: Bool {
|
||||
return self.rawValue == 2
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user