mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-18 07:44:26 +01:00
new: watchOS watch end app
This commit is contained in:
54
ios/WatchApp/PhoneConnMgr.swift
Normal file
54
ios/WatchApp/PhoneConnMgr.swift
Normal file
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// PhoneConnMgr.swift
|
||||
// WatchEnd Watch App
|
||||
//
|
||||
// Created by lolli on 2023/9/16.
|
||||
//
|
||||
|
||||
import WatchConnectivity
|
||||
|
||||
class PhoneConnMgr: NSObject, WCSessionDelegate, ObservableObject {
|
||||
var session: WCSession?
|
||||
var _ctx: [String: Any] = [:]
|
||||
var ctx: [String: Any] {
|
||||
set {
|
||||
Store.setCtx(newValue)
|
||||
updateUrls(newValue)
|
||||
}
|
||||
get {
|
||||
return _ctx
|
||||
}
|
||||
}
|
||||
@Published var urls: [String] = []
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
if !WCSession.isSupported() {
|
||||
print("WCSession not supported")
|
||||
}
|
||||
session = WCSession.default
|
||||
session?.delegate = self
|
||||
session?.activate()
|
||||
|
||||
ctx = Store.getCtx()
|
||||
print("init", ctx)
|
||||
}
|
||||
|
||||
func updateUrls(_ val: [String: Any]) {
|
||||
if let urls = val["urls"] as? [String] {
|
||||
self.urls = urls.filter { !$0.isEmpty }
|
||||
}
|
||||
}
|
||||
|
||||
func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
|
||||
|
||||
}
|
||||
|
||||
// implement session:didReceiveApplicationContext:
|
||||
func session(_ session: WCSession, didReceiveApplicationContext applicationContext: [String : Any]) {
|
||||
ctx = applicationContext
|
||||
print("update", ctx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user