Michel
Michel

Reputation: 11753

watchOS simple wakeup

Here is some watchOS code I have working on the Similator(Watch):

.....
let interval = 60.0
NSTimer.scheduledTimerWithTimeInterval(interval,
                                       target: self,
                                       selector: #selector(InterfaceController.timerDidEnd(_:)),
                                       userInfo: nil, repeats: false)
.....

func timerDidEnd(timer:NSTimer) {
    print("Time is over! Please wake up!")
}

From Xcode I run the app, the first part of the code above gets executed. Then I hit Command-Shift-H and the app goes in the background.

After one minute I see in the debugging console the message: Time is over! Please wake up!

All works as I expect. My question is:

What should I write inside the function timerDidEnd(), in order to have the app wake up from the background on the simulator, rather than just printing the current message in the debugger?

Upvotes: 0

Views: 294

Answers (1)

user4151918
user4151918

Reputation:

There's nothing you can write inside a timer action that will bring an app to the foreground. Only the user can resume an app.

If you think about it, it would confusing and disruptive for the user if an app could programmatically bring itself to the foreground whenever it wanted.

The only way to resume an app is by the user reacting to a notification. This is similar to what happens on the phone when the user taps notification actions from the home screen.

Upvotes: 1

Related Questions