import Flutter
import UIKit
import UMCommon

public class FlutterUmengPlugin: NSObject, FlutterPlugin {
  public static func register(with registrar: FlutterPluginRegistrar) {
    let channel = FlutterMethodChannel(name: "flutter_umeng", binaryMessenger: registrar.messenger())
    let instance = FlutterUmengPlugin()
    registrar.addMethodCallDelegate(instance, channel: channel)
  }

  public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
    switch call.method {
    case "initCommon":
      initialize()
    case "setPolicyGrantResult":
      // initialize()
      break
    default:
      result(FlutterMethodNotImplemented)
    }
  }

  // 初始化
  public func initialize() {
    //设置AppKey，初始化友盟所有组件产品，开发者在友盟官网申请的appkey
    UMConfigure.initWithAppkey("66b07337cac2a664de82d457", channel: "AppStore")
    print("ios友盟初始化")
  }
}
