Detect if the application in background or foreground in swift

后端 未结 5 2302
醉梦人生
醉梦人生 2020-12-04 17:43

is there any way to know the state of my application if it is in background mode or in foreground . Thanks

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 17:56

    you can add a boolean when the application enter in background or enter in foreground. You have this information by using the App delegate.

    According the Apple documentation, maybe you can also use the mainWindow property of your Application or the active status property of the app.

    NSApplication documentation

    Discussion The value in this property is nil when the app’s storyboard or nib file has not yet finished loading. It might also be nil when the app is inactive or hidden.

提交回复
热议问题