Skip to content

Commit

Permalink
fix: resolve compilation issue with watchOS 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
crleona committed Jun 11, 2024
1 parent e0e47a7 commit 03065c5
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions Sources/Amplitude/Plugins/watchOS/WatchOSLifecycleMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@
class WatchOSLifecycleMonitor: UtilityPlugin {
var wasBackgrounded: Bool = false

private var watchExtension = WKApplication.shared()
private var appNotifications: [NSNotification.Name] = [
WKApplication.willEnterForegroundNotification,
WKApplication.didEnterBackgroundNotification,
WKExtension.applicationWillEnterForegroundNotification,
WKExtension.applicationDidEnterBackgroundNotification,
]

override init() {
watchExtension = WKApplication.shared()
super.init()
setupListeners()
}

@objc
func notificationResponse(notification: NSNotification) {
switch notification.name {
case WKApplication.willEnterForegroundNotification:
case WKExtension.applicationWillEnterForegroundNotification:
self.applicationWillEnterForeground(notification: notification)
case WKApplication.didEnterBackgroundNotification:
case WKExtension.applicationDidEnterBackgroundNotification:
self.applicationDidEnterBackground(notification: notification)
default:
break
Expand All @@ -51,18 +49,11 @@
}

func applicationWillEnterForeground(notification: NSNotification) {
// watchOS will receive this after didFinishLaunching, which is different
// from iOS, so ignore until we've been backgrounded at least once.
if wasBackgrounded == false { return }

let timestamp = Int64(NSDate().timeIntervalSince1970 * 1000)
self.amplitude?.onEnterForeground(timestamp: timestamp)
}

func applicationDidEnterBackground(notification: NSNotification) {
// make sure to denote that we were backgrounded.
wasBackgrounded = true

let timestamp = Int64(NSDate().timeIntervalSince1970 * 1000)
self.amplitude?.onExitForeground(timestamp: timestamp)
}
Expand Down

0 comments on commit 03065c5

Please sign in to comment.