20240903 pre release

This commit is contained in:
2024-09-03 22:17:09 +09:00
parent fe46d46ab6
commit 2c0bb06e74
44 changed files with 610 additions and 154 deletions

View File

@ -1,13 +1,58 @@
import Flutter
import UIKit
import CoreMotion
@main
@objc class AppDelegate: FlutterAppDelegate {
private let motionManager = CMMotionManager()
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
//GeneratedPluginRegistrant.register(with: self)
//return super.application(application, didFinishLaunchingWithOptions: launchOptions)
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let motionChannel = FlutterMethodChannel(name: "com.yourcompany.app/motion",
binaryMessenger: controller.binaryMessenger)
motionChannel.setMethodCallHandler({
[weak self] (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
guard let self = self else { return }
switch call.method {
case "startMotionUpdates":
self.startMotionUpdates(result: result)
case "stopMotionUpdates":
self.stopMotionUpdates(result: result)
default:
result(FlutterMethodNotImplemented)
}
})
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
private func startMotionUpdates(result: @escaping FlutterResult) {
if motionManager.isDeviceMotionAvailable {
motionManager.deviceMotionUpdateInterval = 0.1
motionManager.startDeviceMotionUpdates(to: .main) { (motion, error) in
DispatchQueue.main.async {
// UI
let appState = UIApplication.shared.applicationState
//
}
}
result(nil)
} else {
result(FlutterError(code: "UNAVAILABLE",
message: "Device motion is not available.",
details: nil))
}
}
private func stopMotionUpdates(result: @escaping FlutterResult) {
motionManager.stopDeviceMotionUpdates()
result(nil)
}
}