Skip to content

Instantly share code, notes, and snippets.

@daniellevass
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniellevass/652c7b57a743f9a8eda8 to your computer and use it in GitHub Desktop.
Save daniellevass/652c7b57a743f9a8eda8 to your computer and use it in GitHub Desktop.
Making use of Glances in an Apple Watch App

#Making Use of Glances in Apple Watch Apps

Finally in our Apple Watch App 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 see the picture they last looked at quickly again. Maybe to help people check if a cat in front of them matches the one they saw on their screen.

iPhone App

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.

Apple Watch App

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.

Imgur

Our Glance storyboard with a separate text and image groups.

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];

Testing

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":

Imgur

edit apple watch scheme

Conclusion

Hopefully that demonstrates how some of the key features of Whiskr work so you too can build your own awesome Apple Watch Apps. We're now waiting excitedly to get our hands our own Apple Watch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment