Files
StackChan/app/ios/Runner/SceneDelegate.swift
袁智鸿 6314188835 prepare v1.1.4 release with native bridge and stability cleanups
- align Android/iOS native bridge implementations and audio handling paths
- improve Bluetooth provisioning/verification flow and related error handling
- refactor WebSocket, music, and device utility logic for more stable behavior
- clean up noisy debug logs and normalize comments across Flutter and native code
- update AR view, dance/agent/device pages, and platform integration details
2026-04-28 10:57:01 +08:00

84 lines
2.8 KiB
Swift

/*
SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
SPDX-License-Identifier: MIT
*/
import Flutter
import NetworkExtension
import CoreLocation
import UIKit
class SceneDelegate: FlutterSceneDelegate,CLLocationManagerDelegate {
private let locationManager = CLLocationManager()
override func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let controller = window?.rootViewController as? FlutterViewController {
NativeBridge.shared.setup(with: controller)
NativeBridge.shared.setMethodCallHandler { [weak self] call, result in
self?.handleMethodCall(call: call, result: result)
}
registerNativeViews(with: controller)
}
locationManager.delegate = self
}
private func registerNativeViews(with controller: FlutterViewController) {
guard let registrar = controller.registrar(forPlugin: "stack_chan") else {
return
}
let robotFactory =
StackChanRobotViewFactory(messenger: controller.binaryMessenger)
registrar.register(robotFactory, withId: "stackchan_robot_view")
let rotaryFactory =
StackChanRotaryRobotViewFactory(messenger: controller.binaryMessenger)
registrar.register(rotaryFactory, withId: "stackchan_rotary_robot_view")
let arViewFactory = StackChanArViewFactory(messenger: controller.binaryMessenger)
registrar.register(arViewFactory, withId: "stackchan_ar_view")
}
private func handleMethodCall(call: FlutterMethodCall, result: @escaping FlutterResult) {
let method = Method.fromString(call.method)
switch method {
case .wifiName:
getWifiName()
case .stopPlayPCM:
NativeBridge.shared.stopPlayPCM()
default:
break
}
}
private func getWifiName() {
switch locationManager.authorizationStatus {
case .authorizedWhenInUse, .authorizedAlways:
fetchWifiInfo()
break
case .denied, .restricted:
break
case .notDetermined:
locationManager.requestWhenInUseAuthorization()
break
default:
break
}
}
private func fetchWifiInfo() {
NEHotspotNetwork.fetchCurrent { network in
if let wifiName = network?.ssid {
NativeBridge.shared.sendMessage(method: .wifiName, wifiName)
}
}
}
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
if manager.authorizationStatus == .authorizedWhenInUse ||
manager.authorizationStatus == .authorizedAlways {
fetchWifiInfo()
}
}
}