Skip to content

Commit

Permalink
SWF-21 basic paradigm for passing account data to root interface cont…
Browse files Browse the repository at this point in the history
…roller
  • Loading branch information
ahm11003 committed Mar 28, 2019
1 parent 24deb73 commit a3682e4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="14490.20"/>
</dependencies>
<scenes>
<!--Main Menu Interface Controller-->
<!--root-->
<scene sceneID="grn-eT-Mhz">
<objects>
<controller fullScreen="YES" id="Qge-pO-HLc" customClass="MainMenuInterfaceController" customModule="SynchronyFinancial_WatchKit_App" customModuleProvider="target">
<controller identifier="root" fullScreen="YES" id="Qge-pO-HLc" customClass="MainMenuInterfaceController" customModule="SynchronyFinancial_WatchKit_App" customModuleProvider="target">
<items>
<button alignment="center" id="8yj-m6-1L9">
<group key="contentGroup" width="1" height="0.5" alignment="left" contentMode="scaleAspectFit" layout="vertical" id="SBG-wc-YDJ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,26 @@
import WatchKit

class ExtensionDelegate: NSObject, WKExtensionDelegate {
var initialDict: [String: [Account]] = [:]

func applicationDidFinishLaunching() {
// Perform any final initialization of your application.
FetchData.attemptLogin { result, error in
switch result {
case true:
FetchData.getAccountInfo { accounts, error in
guard error == nil else {
NSLog("Account Retrieval Error: %s", error?.localizedDescription ?? "")
return
}

self.initialDict.updateValue(accounts, forKey: "accts")
WKInterfaceController.reloadRootControllers(withNames: ["root"], contexts: [self.initialDict])
}
case false:
NSLog("Login Error: %s", error?.localizedDescription ?? "Unknown Error")
}
}
}

func applicationDidBecomeActive() {
Expand Down Expand Up @@ -56,5 +73,4 @@ class ExtensionDelegate: NSObject, WKExtensionDelegate {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,31 @@ class MainMenuInterfaceController: WKInterfaceController {
override func awake(withContext context: Any?) {
super.awake(withContext: context)

// We should find a better place for this call, just for testing purposes
FetchData.attemptLogin { result, error in
switch result {
case true:
FetchData.getAccountInfo { accounts, error in
guard error == nil else {
NSLog("Account Retrieval Error: %s", error?.localizedDescription ?? "")
return
}

self.acctDict["accts"] = accounts
}
case false:
NSLog("Login Error: %s", error?.localizedDescription ?? "Unknown Error")
}
guard let initial = context as? [String: [Account]], let accts = initial["accts"] else {
presentAlert(withTitle: "Loading Accounts", message: nil, preferredStyle: .alert, actions: [WKAlertAction(title: "Cancel", style: .cancel, handler: {
self.dismiss()
})])
NSLog("Error getting context from WKExtensionDelegate")
return
}

acctDict.updateValue(accts, forKey: "accts")
// We should find a better place for this call, just for testing purposes
// FetchData.attemptLogin { result, error in
// switch result {
// case true:
// FetchData.getAccountInfo { accounts, error in
// guard error == nil else {
// NSLog("Account Retrieval Error: %s", error?.localizedDescription ?? "")
// return
// }
//
// self.acctDict["accts"] = accounts
// }
// case false:
// NSLog("Login Error: %s", error?.localizedDescription ?? "Unknown Error")
// }
// }
//just here for testing. Should be moved into the accounts controller when that branch is merged
// FetchData.getAccountInfo()

Expand Down

0 comments on commit a3682e4

Please sign in to comment.