10. TECH: How to Use ‘Glances’ in Apple Watch Apps
Welcome to the last blog in our Apple Watch App blog series. Out of all our explorations, one of the features we really wanted to try out was glances. These allow people a “quick look” at some important information. In Whiskr we wanted people to be able to quickly see the picture they last looked at. Maybe to help people check if a cat in front of them matches the one they saw on their screen for example.
To get started with glances, we need to save the last image viewed. We will need to use the information from this blog on how to save data between iPhone and Apple Watch app using User Preferences.
Next, we need to open the Apple Watch App Storyboard and navigate to the glance interface controller. There are some annoying storyboard restrictions with the glances, you have to have two different groups, you can’t have one single group. You also can’t have your content scrolling, it has to fit exactly on the view.
Inside our GlanceInterfaceController.m file, we can set up a function to get the saved image from User Preferences (using the same blog post). I also saved a separate String value for the title and copyright information for each picture, so this could be easily viewable.
The complicated bit in glances is how to update the information, e.g. how often should we update the picture? Apple recommend setting up a NSTimer to refresh all the data. How often you want to refresh could be up to you. We decided on 30 seconds…
//schedule a time to check every 5 seconds _timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(getUserDefaults) userInfo:nil repeats:YES];
You also need to remember to stop the timer when the glance closes:
//kill our timer! [_timer invalidate];
We need to tell our emulator to run the “glances” mode and not the proper Apple Watch App. To do this, click on the target for the emulator (bit to the left of which device your going to run on) and press edit scheme.
Here you want to change the executable to the “glance”:
Hopefully that demonstrates how some of the key features of Whiskr work so you too can build your own awesome Apple Watch Apps. Whiskr has now been submitted to the Apple app store so we’re just waiting for the app to be submitted and of course we’re also waiting excitedly to get our hands our own Apple Watch!
We hope you have found this blog series useful. If you would like to know more about Whiskr or Calvium or to share your own Apple Watch developments with us, please get in touch.