There are two ways in which we can go about creating WatchKit context menu items. In the previous section, we discussed how we can drag and drop a WKInterfaceMenu
control in InterfaceController
within the storyboard that will contain the menu.
You can also create them programmatically using the WKInterfaceController
method and provide an image, a title, and the associated action method that will get executed when the menu item is tapped by the user. Simply perform the following steps:
Open the
InterfaceController.swift
file located within the ShoppingList WatchKit Extension group from the project navigation window.Next, locate the
awakeWithContext
method and enter the following highlighted code snippet:override func awakeWithContext(context: AnyObject?) { super.awakeWithContext(context) // Perform any final initialization of your application. if WCSession.isSupported() { let session = WCSession.defaultSession() ...