diff --git a/Sources/Amplitude/Amplitude.swift b/Sources/Amplitude/Amplitude.swift index 8a934352..6edf1945 100644 --- a/Sources/Amplitude/Amplitude.swift +++ b/Sources/Amplitude/Amplitude.swift @@ -119,7 +119,9 @@ public class Amplitude { func onExitForeground() { inForeground = false - _ = self.flush() + if configuration.flushEventsOnClose == true { + _ = self.flush() + } } public func apply(closure: (Plugin) -> Void) { diff --git a/Sources/Amplitude/Plugins/Mac/MacOSLifecycleMonitor.swift b/Sources/Amplitude/Plugins/Mac/MacOSLifecycleMonitor.swift index ad9651ed..58a9349c 100644 --- a/Sources/Amplitude/Plugins/Mac/MacOSLifecycleMonitor.swift +++ b/Sources/Amplitude/Plugins/Mac/MacOSLifecycleMonitor.swift @@ -64,7 +64,7 @@ } func applicationDidBecomeActive(notification: NSNotification) { - analytics?.apply { (ext) in + amplitude?.apply { (ext) in if let validExt = ext as? MacOSLifecycle { validExt.applicationDidBecomeActive() } @@ -72,7 +72,7 @@ } func applicationWillResignActive(notification: NSNotification) { - analytics?.apply { (ext) in + amplitude?.apply { (ext) in if let validExt = ext as? MacOSLifecycle { validExt.applicationWillResignActive() } @@ -80,17 +80,6 @@ } } - extension AmplitudeDestinationPlugin: MacOSLifecycle { - public func applicationWillEnterForeground(application: UIApplication?) { - let timestamp = NSDate().timeIntervalSince1970 - self.amplitude?.onEnterForeground(timestamp: timestamp) - } - - public func applicationDidEnterBackground(application: UIApplication?) { - self.amplitude?.onExitForeground() - } - } - extension AmplitudeDestinationPlugin: MacOSLifecycle { public func applicationDidBecomeActive() { let timestamp = NSDate().timeIntervalSince1970 diff --git a/Sources/Amplitude/Plugins/Vendors/AppUtil.swift b/Sources/Amplitude/Plugins/Vendors/AppUtil.swift index 6e3122f2..95bb4a8c 100644 --- a/Sources/Amplitude/Plugins/Vendors/AppUtil.swift +++ b/Sources/Amplitude/Plugins/Vendors/AppUtil.swift @@ -12,7 +12,7 @@ } #endif -#if os(watchOS) +#if os(macOS) internal class MacOSVendorSystem: VendorSystem { override var requiredPlugin: Plugin { return MacOSLifecycleMonitor() diff --git a/Sources/Amplitude/Plugins/Vendors/VendorSystem.swift b/Sources/Amplitude/Plugins/Vendors/VendorSystem.swift index 5aa1c3eb..c4dc50f5 100644 --- a/Sources/Amplitude/Plugins/Vendors/VendorSystem.swift +++ b/Sources/Amplitude/Plugins/Vendors/VendorSystem.swift @@ -13,8 +13,6 @@ internal class VendorSystem { return MacOSVendorSystem() #elseif os(watchOS) return WatchOSVendorSystem() - #elseif os(Linux) - return LinuxVendorSystem() #else return VendorSystem() #endif diff --git a/Sources/Amplitude/Plugins/iOS/IOSLifecycleMonitor.swift b/Sources/Amplitude/Plugins/iOS/IOSLifecycleMonitor.swift index 25efc70f..9320e079 100644 --- a/Sources/Amplitude/Plugins/iOS/IOSLifecycleMonitor.swift +++ b/Sources/Amplitude/Plugins/iOS/IOSLifecycleMonitor.swift @@ -8,7 +8,7 @@ #if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst) import Foundation - import UIKit + import SwiftUI public protocol IOSLifecycle { func applicationDidEnterBackground(application: UIApplication?) diff --git a/Sources/Amplitude/Plugins/watchOS/WatchOSLifecycleMonitor.swift b/Sources/Amplitude/Plugins/watchOS/WatchOSLifecycleMonitor.swift index 05fdc803..29ebe3dc 100644 --- a/Sources/Amplitude/Plugins/watchOS/WatchOSLifecycleMonitor.swift +++ b/Sources/Amplitude/Plugins/watchOS/WatchOSLifecycleMonitor.swift @@ -67,7 +67,7 @@ // from iOS, so ignore until we've been backgrounded at least once. if wasBackgrounded == false { return } - analytics?.apply { (ext) in + amplitude?.apply { (ext) in if let validExt = ext as? WatchOSLifecycle { validExt.applicationWillEnterForeground(watchExtension: watchExtension) } @@ -78,7 +78,7 @@ // make sure to denote that we were backgrounded. wasBackgrounded = true - analytics?.apply { (ext) in + amplitude?.apply { (ext) in if let validExt = ext as? WatchOSLifecycle { validExt.applicationDidEnterBackground(watchExtension: watchExtension) }