Flutter 如何实现颤振插件的委托

Flutter 如何实现颤振插件的委托,flutter,dart,Flutter,Dart,我正在测试iOS后台服务以获得位置更新。在本机swift上成功地执行了,但是当我尝试使用flatter插件失败时,代理服务似乎不起作用,下面是我在flatter插件中的示例代码 import Flutter import CoreLocation import UIKit @available(iOS 9.0, *) public class SwiftSimpleBackgroundGeolocationPlugin: NSObject, FlutterPlugin, CLLocationM

我正在测试iOS后台服务以获得位置更新。在本机swift上成功地执行了,但是当我尝试使用flatter插件失败时,代理服务似乎不起作用,下面是我在flatter插件中的示例代码

import Flutter
import CoreLocation
import UIKit

@available(iOS 9.0, *)
public class SwiftSimpleBackgroundGeolocationPlugin: NSObject, FlutterPlugin, CLLocationManagerDelegate {

    static var channel: FlutterMethodChannel?

    public static func register(with registrar: FlutterPluginRegistrar) {
        let instance = SwiftSimpleBackgroundGeolocationPlugin()

        SwiftSimpleBackgroundGeolocationPlugin.channel = FlutterMethodChannel(name: "simple_background_geolocation", binaryMessenger: registrar.messenger())
        registrar.addMethodCallDelegate(instance, channel: SwiftSimpleBackgroundGeolocationPlugin.channel!)
        SwiftSimpleBackgroundGeolocationPlugin.channel?.setMethodCallHandler(instance.handle)
    }

    public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {

        let   locationManager  = CLLocationManager()
        locationManager.delegate = self

        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.allowsBackgroundLocationUpdates = true
        locationManager.pausesLocationUpdatesAutomatically = false
        locationManager.requestAlwaysAuthorization()

        locationManager.startUpdatingLocation();
    }