File tree Expand file tree Collapse file tree
lifecycletracker/src/iosMain/kotlin/com.multiplatform.lifecyle Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com.multiplatform.lifecyle
2+
3+ import com.multiplatform.lifecycle.LifecycleEvent
4+ import com.multiplatform.lifecycle.LifecycleTracker
5+ import kotlinx.cinterop.BetaInteropApi
6+ import kotlinx.cinterop.ObjCAction
7+ import platform.Foundation.NSNotification
8+ import platform.darwin.NSObject
9+
10+ /* *
11+ * Created By Kevin Zou On 2024/2/26
12+ */
13+ @Suppress(" unused" )
14+ @OptIn(BetaInteropApi ::class )
15+ class NSLifecycleListener (private val lifecycleTracker : LifecycleTracker ) : NSObject() {
16+
17+ @ObjCAction
18+ fun willEnterForeground (arg : NSNotification ) {
19+ lifecycleTracker.notifyListeners(LifecycleEvent .OnStartEvent )
20+ }
21+
22+ @ObjCAction
23+ fun didBecomeActive (arg : NSNotification ) {
24+ lifecycleTracker.notifyListeners(LifecycleEvent .OnResumeEvent )
25+ }
26+
27+ @ObjCAction
28+ fun willResignActive (arg : NSNotification ) {
29+ lifecycleTracker.notifyListeners(LifecycleEvent .OnPauseEvent )
30+ }
31+
32+ @ObjCAction
33+ fun didEnterBackground (arg : NSNotification ) {
34+ lifecycleTracker.notifyListeners(LifecycleEvent .OnStopEvent )
35+ }
36+
37+ @ObjCAction
38+ fun willTerminate (arg : NSNotification ) {
39+ lifecycleTracker.notifyListeners(LifecycleEvent .OnDestroyEvent )
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments