Skip to content

Commit

Permalink
fix: set application as a computed property
Browse files Browse the repository at this point in the history
  • Loading branch information
PouriaAmini committed Jul 2, 2024
1 parent 3d04695 commit 12f9967
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Sources/Amplitude/Plugins/iOS/IOSLifecycleMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import Foundation
import SwiftUI

class IOSLifecycleMonitor: UtilityPlugin {
private var application: UIApplication?
private var application: UIApplication? {
// TODO: Check if lifecycle plugin works for app extension
// App extensions can't use UIApplication.shared, so
// funnel it through something to check; Could be nil.
UIApplication.value(forKeyPath: "sharedApplication") as? UIApplication
}

private var appNotifications: [NSNotification.Name] = [
UIApplication.didEnterBackgroundNotification,
UIApplication.willEnterForegroundNotification,
Expand All @@ -22,10 +28,6 @@ class IOSLifecycleMonitor: UtilityPlugin {
private var sendApplicationOpenedOnDidBecomeActive = false

override init() {
// TODO: Check if lifecycle plugin works for app extension
// App extensions can't use UIApplication.shared, so
// funnel it through something to check; Could be nil.
application = UIApplication.value(forKeyPath: "sharedApplication") as? UIApplication
super.init()
setupListeners()
}
Expand Down

0 comments on commit 12f9967

Please sign in to comment.