temporary update

This commit is contained in:
2024-09-08 18:16:51 +09:00
parent 2c0bb06e74
commit e37c4ceebd
32 changed files with 1235 additions and 1189 deletions

View File

@ -12,8 +12,9 @@ import CoreMotion
) -> 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",
let motionChannel = FlutterMethodChannel(name: "net.sumasen.gifunavi/motion",
binaryMessenger: controller.binaryMessenger)
motionChannel.setMethodCallHandler({
[weak self] (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
@ -33,17 +34,58 @@ import CoreMotion
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
//
// 姿
//
// sendMotionData使Flutter
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
//
}
motionManager.startDeviceMotionUpdates(to: .main) { [weak self] (motion, error) in
guard let self = self else { return }
if let error = error {
DispatchQueue.main.async {
result(FlutterError(code: "MOTION_ERROR",
message: error.localizedDescription,
details: nil))
}
return
}
guard let motion = motion else {
DispatchQueue.main.async {
result(FlutterError(code: "NO_MOTION_DATA",
message: "No motion data available",
details: nil))
}
return
}
DispatchQueue.main.async {
let motionData: [String: Any] = [
"attitude": [
"roll": motion.attitude.roll,
"pitch": motion.attitude.pitch,
"yaw": motion.attitude.yaw
],
"gravity": [
"x": motion.gravity.x,
"y": motion.gravity.y,
"z": motion.gravity.z
],
"userAcceleration": [
"x": motion.userAcceleration.x,
"y": motion.userAcceleration.y,
"z": motion.userAcceleration.z
]
]
self.sendMotionData(motionData)
}
}
result(nil)
result(nil) //
} else {
result(FlutterError(code: "UNAVAILABLE",
message: "Device motion is not available.",
@ -51,6 +93,12 @@ import CoreMotion
}
}
private func sendMotionData(_ data: [String: Any]) {
let motionChannel = FlutterMethodChannel(name: "net.sumasen.gifunavi/motion",
binaryMessenger: (window?.rootViewController as! FlutterViewController).binaryMessenger)
motionChannel.invokeMethod("onMotionData", arguments: data)
}
private func stopMotionUpdates(result: @escaping FlutterResult) {
motionManager.stopDeviceMotionUpdates()
result(nil)