Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
by
Lessons:19Length:2.3 hours
  • Overview
  • Transcript

4.5 The Final State and Haptics

In this lesson, in addition to completing the final state, we also want to be able to provide a simple notification to the user that a stage has completed. For this we are going to use haptics. In this lesson, I'll explain what haptics are and how to use them.

4.5 The Final State and Haptics

Okay, so we've finally gotten down to a point where we have reached the end of an entire reminder. We've gone through all the stages, everything has finished up, and now we want to be able to reset this particular reminder so we could do it again if we want to. And that's where we're gonna use this reset function, right here. So this is gonna be pretty basic, I'm simply going to reset the state back to a ready state so I can start all over if I want. And at this point I need to set the active stage back to the very beginning. So in this case I will say that the active is gonna be equal to the activeReminder.stages. And I wanna go get number zero I want to go get the very first one in that list. Then finally, I want to reset the action button title, so I'll say actionbutton.settitle and I'll simply put it back to start, just like that. So let's go ahead and save this. Let's run through this one time really quickly so we can actually see it running. And while this is coming up, let's take a minute to talk a little bit about some notification mechanism that you have access to on the watch. Now yes, you can provide visual cues and all sorts of things like that, but one of the things that's also included in the Apple Watch is this concept of a haptic. And what exactly does that mean? Well, that means it's kind of a nudging or a vibration type feel that you can do at certain times. And you get programmatic access to that using the WK interface device, and I'm gonna show you how to do that right after this. So I can go ahead and select my morning wake up. Let's go ahead and start this one. We're going to count down to zero in two, one, zero. Then we're gonna see that we can go to the next stage which is going to be a light jog. We'll go ahead and start that. I can end that stage it's gonna fast forward down to zero, I can say next stage. And notice that they are no more, and then I get my reset button. So I'll go ahead and click reset and it's gonna take me back to the very first one, which was stretched for five seconds. And I could go ahead and continue on. As you can see, I get into this kind of circular loop work where I can go all the way through and check all of them out. And once again I could cancel this, I can go to my evening wind-down and do the exact same thing. So I can start off at 20 seconds, I can fast-forward to the end of that one. I can switch to the next one, which is take a 60-second snack. And then I can go ahead and finish that up, if I'm not interested, and go back to reset, and go back to the beginning. So now you have this concept of a full-state machine that's gonna keep track of these different stages and where you are along the pipeline. And then transition seamlessly from one state to the next. Okay, and as I mentioned before, there is a mechanism where you can kind of provide a little bit of a vibration or something to the end user So that they know when something has happened. Now we can do that using the W-K interface device. So where we're gonna stick this is, is when the timer has actually ended. So when we actually get to a point where a timer has ended, not necessarily where skipping something like that, so when the actual timer Has fired into our timerEnded function here. I wanna give a little bit of a notification. So after we invalidate this we're gonna use the WKInterfaceDevice and then we can use the current function which is going to give us the current device and then we say we want to play And we want to play a haptic type. Now there's a number of different types of these. This is actually an enumeration. So you can pick all sorts of different types of these. Now each one of these different types of haptic types have some sort of different feel to them. And I think probably the stop is a little bit more interesting of one as it provides probably the most noticeable Now where it gives you kind of two pulses. So, I think that would be pretty cool to do to the end user. Now unfortunately, you really can't notice this when you are doing this through the simulator. If you were to hook this up through an actual device, you would notice this actual haptic being played on your device. Which is pretty cool. So now we've gotten to a point where we have created all of the different states and we can transition between all of them and there's just one more little thing I wanna show you in the next lesson to help kind of bridge the gap between our watch kit application and maybe something that would actually be running on the iPhone

Back to the top