temporary update
This commit is contained in:
@ -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)
|
||||
|
||||
@ -19,26 +19,37 @@
|
||||
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="岐阜ナビ" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WPs-nj-CIV">
|
||||
<rect key="frame" x="46" y="123" width="314" height="59"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="岐阜ナビ" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WPs-nj-CIV">
|
||||
<rect key="frame" x="36" y="123.99999999999999" width="321" height="38.333333333333329"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="32"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="NPO 岐阜aiネットワーク" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TM1-SD-6RA">
|
||||
<rect key="frame" x="46" y="722" width="314" height="41"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="NPO 岐阜aiネットワーク" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TM1-SD-6RA">
|
||||
<rect key="frame" x="36" y="717.66666666666663" width="321" height="20.333333333333371"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="LaunchImage" translatesAutoresizingMaskIntoConstraints="NO" id="hCH-Iu-4S2">
|
||||
<rect key="frame" x="83" y="314" width="240" height="224"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="LaunchImage" translatesAutoresizingMaskIntoConstraints="NO" id="hCH-Iu-4S2">
|
||||
<rect key="frame" x="36" y="212.33333333333334" width="321" height="405.33333333333326"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" secondItem="hCH-Iu-4S2" secondAttribute="height" multiplier="270:341" id="jg6-gh-iGg"/>
|
||||
</constraints>
|
||||
</imageView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailingMargin" secondItem="WPs-nj-CIV" secondAttribute="trailing" constant="20" id="1UA-eg-bma"/>
|
||||
<constraint firstAttribute="trailingMargin" secondItem="hCH-Iu-4S2" secondAttribute="trailing" constant="20" id="3lP-Fl-Xzw"/>
|
||||
<constraint firstAttribute="trailingMargin" secondItem="TM1-SD-6RA" secondAttribute="trailing" constant="20" id="E8j-R8-JVy"/>
|
||||
<constraint firstItem="xbc-2k-c8Z" firstAttribute="top" secondItem="TM1-SD-6RA" secondAttribute="bottom" constant="80" id="MKZ-EI-0XJ"/>
|
||||
<constraint firstItem="hCH-Iu-4S2" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leadingMargin" constant="20" id="N5f-Kk-hnZ"/>
|
||||
<constraint firstItem="TM1-SD-6RA" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leadingMargin" constant="20" id="OUN-wm-60h"/>
|
||||
<constraint firstItem="WPs-nj-CIV" firstAttribute="top" secondItem="Ydg-fD-yQy" secondAttribute="bottom" constant="65" id="aPG-JX-zf5"/>
|
||||
<constraint firstItem="hCH-Iu-4S2" firstAttribute="top" secondItem="WPs-nj-CIV" secondAttribute="bottom" constant="50" id="jKu-Hc-2ln"/>
|
||||
<constraint firstItem="WPs-nj-CIV" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leadingMargin" constant="20" id="u9d-2i-Jy1"/>
|
||||
</constraints>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
|
||||
Reference in New Issue
Block a user