Skip to content

Code snippets using WatchKit for making Apple Watch Apps.

Notifications You must be signed in to change notification settings

MaorS/ios-watchkit-snippets

 
 

Repository files navigation

ios-watchkit-snippets

##Description Code snippets using WatchKit for making Apple Watch Apps. Each folder in this repo represents a different project described below.

icon

##Language Swift

###Project: HelloWatch

icon

  • A Simple 'Hello World' Apple Watch app.
  • To run the Apple Watch app in the Simulator, simply choose the 'WatchKit App' target.
  • Once the iPhone simulator is running, you may also need to navigate to iOS Simulator--> Hardware --> External Displays --> Apple Watch.

###Project: WatchButton

icon

  • Demonstrates using an IBAction for handling button tap event.
  • Uses an IBOutlet to allow for programmatically updating the label's text.
  • Uses a custom image asset when presenting a button.

###Project: WatchImage (and Switch)

icon

  • Demonstrates using an IBAction for handling Switch event.
  • Uses an IBOutlet to allow for programmatically setting an Image.

Shout out to Filipe de Carvalho for the awesome art work!

###Project: WatchTable

icon

  • Demonstrates a scrollable table interface.
  • Adding a Table to the Interface.storyboard.
  • Creating a row 'template' with an image and a label.
  • Creating a TableRowController class in the WatchKit Extension target.
  • Using the Identity Inspector to explicitly declare the TableRowController to be used by the Interface.storyboard.
  • Populating table rows based on a Collection of Dictionaries.

###Project: WatchPageNavigation

icon

  • Demonstrates setting up an App that uses Page based Navigation whereby a user can swipe right-left to move between different screens.
  • Creating three distinct WKInterfaceController sub-classes - one for each page.
  • In Interface.storyboard, adding a new InterfaceController for each page in the story board and explicitly declaring that InterfaceController's class in the Identity Inspector.
  • Creating a segue between InterfaceController scenes.

###Project: WatchHierarchicalNavigation

icon

  • Demonstrates setting up an App that uses Hierarchical Navigation or master-detail navigation - whereby a user can navigate to different screens and tap a 'back button' to go to the previous.
  • The TableInterfaceController is the WKInterfaceController subclass for the table screen. This class is responsible for; programmatically populating the table rows and handling the passing of data from a tapped row to the DetailInterfaceController.
  • The TableInterfaceController scene is composed of a Table that uses the TableRowController to define the data for populating each row's label and image.
  • The DetailInterfaceController is the WKInterfaceController subclass which is responsible for presenting the 'details' for the table row that a user tapped on.
  • In Interface.storyboard, a push segue is created between the row and the DetailInterfaceController scene. This segue has the identifier DetailsSegue.
  • Data is passed from the TableInterfaceController using the contextForSegueWithIdentifier method.
  • Data is received by the DetailInterfaceController in the awakeWithContext method.

###Project: WatchMap

icon

  • Demonstrates adding a Map to your Apple Watch App.
  • A map is added to the Interface.storyboard.
  • Inside the WKInterfaceController subclass, the maps default center and zoom level is set.
  • A red pin annotation is added to the center of the map.

###Project: WatchMapUserLocation

icon

  • Demonstrates zooming a map to the User's Location.
  • Adding CoreLocation.framework to your iPhone app (and adding required Info.plist entries).
  • In the WKInterfaceController subclass; importing Core Location, adding a CLLocationManager property, and implementing CLLocationManagerDeletate protocol methods.
  • Using the locationManager:didUpdateLocations method to fetch the user's location and center the map.

###Deploying to your Apple Watch for Testing To run an Xcode project on your Apple Watch, do the following:

  • Connect your iOS device to your Mac.
  • In Xcode, go to Window --> Devices and confirm that Xcode recognizes that your Apple Watch is paired with your iPhone device (see screenshot below).

icon

  • Choose the 'WatchKit App' target and your device to run.
  • Test the app on your watch!
  • To remove your app from your Apple Watch, use the Apple Watch App on your iPhone to not show it. To remove the app from both the Apple Watch and iPhone, simply delete the app from your iPhone.

##Connect

About

Code snippets using WatchKit for making Apple Watch Apps.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%