3

I need to know if there is an event in the AppDelegate.swift that is triggered when the phone has been locked because of the autolock time exceeded

I have tried to use the applicationDidEnterBackground method but It is not triggered because in that case the app is still in foreground

2 Answers2

0

There is no official way of doing this.

There are a few hacks floating around, but you shouldn't use them (your app could get rejected from the app store if you do use them).

Antag
  • 230
  • 3
  • 12
0

You can implement applicationWillResignActive method in AppDelegate and check if brightness is changed to 0.0 as below,

func applicationWillResignActive(_ application: UIApplication) {
    if UIScreen.main.brightness == 0.0 {
        print("App is locked!")
    }
} 
Kamran
  • 14,987
  • 4
  • 33
  • 51