This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InterfaceController: WKInterfaceController, WCSessionDelegate { | |
// ... | |
override func awake(withContext context: Any?) { | |
super.awake(withContext: context) | |
// Configure interface objects here. | |
messages.append("We are ready!!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import WatchKit | |
import Foundation | |
import WatchConnectivity | |
class InterfaceController: WKInterfaceController { | |
// 1: Session property | |
private var session = WCSession.default | |
@IBOutlet weak var table: WKInterfaceTable! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import WatchConnectivity | |
class SessionHandler : NSObject, WCSessionDelegate { | |
// 1: Singleton | |
static let shared = SessionHandler() | |
// 2: Property to manage session |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
// 1: Import Framework | |
import WatchConnectivity | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController { | |
// 1: Get singleton class whitch manage WCSession | |
var connectivityHandler = SessionHandler.shared | |
// 2: Counter for manage number of messages sended | |
var messagesCounter = 0 | |
// ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Receive messages from iPhone | |
func session(_ session: WCSession, didReceiveMessage message: [String : Any]) { | |
// 1: We launch a sound and a vibration | |
WKInterfaceDevice.current().play(.notification) | |
// 2: Get message and append to list | |
let msg = message["msg"]! | |
self.items.append("\(msg)") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import WatchKit | |
import WatchConnectivity | |
// 1: Encapsulating in a tuple for don't duplicate code | |
typealias MessageReceived = (session: WCSession, message: [String : Any], replyHandler: (([String : Any]) -> Void)?) | |
// 2: Protocol for manage all watchOS delegations | |
protocol WatchOSDelegate: AnyObject { | |
func messageReceived(tuple: MessageReceived) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
WatchSessionManager.shared.startSession() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import WatchConnectivity | |
class ViewController: UIViewController { | |
var connectivityHandler = WatchSessionManager.shared | |
var counter = 0 | |
override func viewDidLoad() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum RequestType: String { | |
case date | |
case version | |
} |