diff --git a/ios/OTL Watch App/ContentView.swift b/ios/OTL Watch App/ContentView.swift index 4bda4200..b59ffa6f 100644 --- a/ios/OTL Watch App/ContentView.swift +++ b/ios/OTL Watch App/ContentView.swift @@ -8,8 +8,6 @@ import SwiftUI struct ContentView: View { - @ObservedObject var viewModel = WatchViewModel() - @State private var loginState: Bool = true var body: some View { diff --git a/ios/OTL Watch App/OTLAPI.swift b/ios/OTL Watch App/OTLAPI.swift index b6137cb1..2db6c2bc 100644 --- a/ios/OTL Watch App/OTLAPI.swift +++ b/ios/OTL Watch App/OTLAPI.swift @@ -215,11 +215,11 @@ class OTLAPI { let json = try decoder.decode([Timetable].self, from: data) completion(.success(json)) } catch { - print("Error: \(error)") + print("getTimetables Error: \(error)") completion(.failure(error)) } case .failure(let error): - print("Error: \(error)") + print("getTimetables Error: \(error)") completion(.failure(error)) } } @@ -235,11 +235,11 @@ class OTLAPI { let json = try decoder.decode([Semester].self, from: data) completion(.success(json)) } catch { - print ("Error \(error)") + print ("getSemesters Error \(error)") completion(.failure(error)) } case .failure(let error): - print("Error: \(error)") + print("getSemesters Error: \(error)") completion(.failure(error)) } } @@ -271,11 +271,11 @@ class OTLAPI { } completion(.success([timetable])) } catch { - print("Error: \(error)") + print("getActualTimetable Error: \(error)") completion(.failure(error)) } case .failure(let error): - print("Error: \(error)") + print("getActualTimetable Error: \(error)") completion(.failure(error)) } } @@ -315,11 +315,11 @@ class OTLAPI { }) completion(.success(semesters)) } catch { - print("Error: \(error)") + print("getActualSemesters Error: \(error)") completion(.failure(error)) } case .failure(let error): - print("Error: \(error)") + print("getActualSemesters Error: \(error)") completion(.failure(error)) } } diff --git a/ios/OTL Watch App/Pages/WeeklyTableView.swift b/ios/OTL Watch App/Pages/WeeklyTableView.swift index e4a122b6..fd608b3f 100644 --- a/ios/OTL Watch App/Pages/WeeklyTableView.swift +++ b/ios/OTL Watch App/Pages/WeeklyTableView.swift @@ -12,6 +12,8 @@ import Alamofire struct WeeklyTableView: View { @Binding var loginState: Bool + @ObservedObject var viewModel = WatchViewModel() + @AppStorage("sessionID") var sessionID: String = "" @AppStorage("userID") var userID: String = "" diff --git a/ios/OTL Watch App/WatchViewModel.swift b/ios/OTL Watch App/WatchViewModel.swift index 23c378b8..28280492 100644 --- a/ios/OTL Watch App/WatchViewModel.swift +++ b/ios/OTL Watch App/WatchViewModel.swift @@ -30,23 +30,6 @@ class WatchViewModel: NSObject, ObservableObject { extension WatchViewModel: WCSessionDelegate { func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) { } - func session(_ session: WCSession, didReceiveMessage message: [String: Any]) { - DispatchQueue.main.async { - guard let rawMethod = message["method"] as? String, let method = WatchReceiveMethod(rawValue: rawMethod) else { - return - } - - switch method { - case .sendSessionID: - self.sessionID = message["data"] as? String ?? "" - UserDefaults.standard.set(message["data"] as? String ?? "", forKey: "sessionID") - case .sendUserID: - self.userID = message["data"] as? String ?? "" - UserDefaults.standard.set(message["data"] as? String ?? "", forKey: "userID") - } - } - } - func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any] = [:]) { DispatchQueue.main.async { guard let rawMethod = userInfo["method"] as? String, let method = WatchReceiveMethod(rawValue: rawMethod) else { diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 84d650c0..9a10dfb2 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -19,7 +19,6 @@ import WatchConnectivity } private func initFlutterChannel() { - print("AppDelegate") if let controller = window?.rootViewController as? FlutterViewController { let channel = FlutterMethodChannel( name: "org.sparcs.otlplus.watchkitapp", @@ -35,18 +34,11 @@ import WatchConnectivity let methodData = call.arguments as? [String: Any], let method = methodData["method"], let data = methodData["data"] else { - print("failllllllll") - print(self?.session?.isPaired) - print("llllllllllll") result(false) return } - print("watchData Start") let watchData: [String: Any] = ["method": method, "data": data] - print(watchData) - print("watchData End") watchSession.transferUserInfo(watchData) -// watchSession.sendMessage(watchData, replyHandler: nil, errorHandler: nil) result(true) default: result(FlutterMethodNotImplemented) @@ -63,13 +55,13 @@ extension AppDelegate: WCSessionDelegate { func sessionDidDeactivate(_ session: WCSession) { } - func session(_ session: WCSession, didReceiveMessage message: [String: Any]) { + func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any] = [:]) { DispatchQueue.main.async { - if let method = message["method"] as? String, let controller = self.window?.rootViewController as? FlutterViewController { + if let method = userInfo["method"] as? String, let controller = self.window?.rootViewController as? FlutterViewController { let channel = FlutterMethodChannel( name: "org.sparcs.otlplus.watchkitapp", binaryMessenger: controller.binaryMessenger) - channel.invokeMethod(method, arguments: message) + channel.invokeMethod(method, arguments: userInfo) } } }