Skip to content

Instantly share code, notes, and snippets.

View litoarias's full-sized avatar
💭
I may be slow to respond.

Lito litoarias

💭
I may be slow to respond.
View GitHub Profile
@litoarias
litoarias / InterfaceController.swift
Created June 14, 2018 18:32
Watch Tutorial - 4
class InterfaceController: WKInterfaceController, WCSessionDelegate {
// ...
override func awake(withContext context: Any?) {
super.awake(withContext: context)
// Configure interface objects here.
messages.append("We are ready!!")
@litoarias
litoarias / InterfaceController.swift
Last active June 16, 2018 14:02
Watch Tutorial - 5
import WatchKit
import Foundation
import WatchConnectivity
class InterfaceController: WKInterfaceController {
// 1: Session property
private var session = WCSession.default
@IBOutlet weak var table: WKInterfaceTable!
@litoarias
litoarias / SessionHandler.swift
Last active June 16, 2018 14:09
Watch Tutorial - 6
import Foundation
import WatchConnectivity
class SessionHandler : NSObject, WCSessionDelegate {
// 1: Singleton
static let shared = SessionHandler()
// 2: Property to manage session
@litoarias
litoarias / AppDelegate.swift
Last active June 15, 2018 16:29
Watch Tutorial - 7
import UIKit
// 1: Import Framework
import WatchConnectivity
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
@litoarias
litoarias / ViewController.swift
Last active June 19, 2018 08:49
Watch Tutorial 8
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
// ...
@litoarias
litoarias / InterfaceController.swift
Last active June 19, 2018 09:59
Watch Tutorial 9
// 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)")
}
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)
@litoarias
litoarias / AppDelegate.swift
Last active June 21, 2018 10:13
Watch Tutorial 11
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
WatchSessionManager.shared.startSession()
@litoarias
litoarias / ViewController.swift
Last active June 21, 2018 10:43
Tutorial Watch 12
import UIKit
import WatchConnectivity
class ViewController: UIViewController {
var connectivityHandler = WatchSessionManager.shared
var counter = 0
override func viewDidLoad() {
@litoarias
litoarias / RequestType.swift
Created June 21, 2018 10:37
Tutorial watch 13
enum RequestType: String {
case date
case version
}