Files
rog_app/lib/services/motion_service.dart
2024-09-03 22:17:09 +09:00

29 lines
881 B
Dart

import 'package:flutter/services.dart';
import 'dart:io';
class MotionService {
static const MethodChannel _channel = MethodChannel('net.sumasen.gifunavi/motion');
static Future<void> startMotionUpdates() async {
if (Platform.isIOS) {
try {
await _channel.invokeMethod('startMotionUpdates');
} on PlatformException catch (e) {
print("Failed to start motion updates: '${e.message}'.");
}
} else{
// Android の場合は何もしない、またはAndroid向けの代替実装を行う
print("Motion updates not supported on this platform");
}
}
static Future<void> stopMotionUpdates() async {
if (Platform.isIOS) {
try {
await _channel.invokeMethod('stopMotionUpdates');
} on PlatformException catch (e) {
print("Failed to stop motion updates: '${e.message}'.");
}
}
}
}