Disable app sleep in Swift

How do I disable an app socket in Swift? I am new to programming and I am creating a timer (just for practice) and I am afraid the sleep app will break my timer.

+3


source to share


2 answers


I found this solution works in Swift as well.

Create a class or global variable

var activity: NSObjectProtocol?

      



And assign it, after which the Nap app will be disabled

activity = NSProcessInfo().beginActivityWithOptions(NSActivityOptions.UserInitiated, reason: "Good Reason")

      

+6


source


Swift 3 :

var activity: NSObjectProtocol?

      



and

activity = ProcessInfo().beginActivity(options: ProcessInfo.ActivityOptions.userInitiated, reason: "Good Reason")

      

+3


source







All Articles