Skip to content
Permalink
e85d2cb36e
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
58 lines (50 sloc) 2.09 KB
//
// MainMenuInterfaceController.swift
// SynchronyFinancial WatchKit Extension
//
// Created by Alan Maynard on 11/21/18.
// Copyright © 2018 Alan Maynard. All rights reserved.
//
import WatchKit
import Foundation
import Alamofire
import SwiftyJSON
class MainMenuInterfaceController: WKInterfaceController {
@IBOutlet weak var accountsButton: WKInterfaceButton!
@IBOutlet weak var wellnessButton: WKInterfaceButton!
override func awake(withContext context: Any?) {
super.awake(withContext: context)
// We should find a better place for this call, just for testing purposes
Alamofire.request(Defaults.LOGIN_URL, method: .post, parameters: Defaults.headerForLogin, encoding: JSONEncoding.default).responseJSON { payload in
switch payload.result {
case .success(let value):
let json = JSON(value)
let dict = json.dictionaryValue
guard dict["status"]?.dictionaryValue["response_code"]?.string == "0" else { return }
if let token = dict["access_token"]?.string {
debugPrint(token)
// now we should save our token somewhere safe (UserDefaults)
UserDefaults.standard.set(token, forKey: "access_token")
}
case .failure(let error):
NSLog("Error: %s", error.localizedDescription)
}
}
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
override func contextForSegue(withIdentifier segueIdentifier: String) -> Any? {
if segueIdentifier == "toAccounts" {
// we will probably want to do some setup prior to presenting Accounts
} else if segueIdentifier == "toWellness" {
// we will probably want to do some setup prior to presenting Wellness
}
return nil
}
}