SwiftFlutterzipPlugin.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import Flutter
  2. import UIKit
  3. //SSZipArchiveDelegate
  4. import SSZipArchive
  5. public class SwiftFlutterzipPlugin: NSObject, FlutterPlugin ,SSZipArchiveDelegate{
  6. var channell : FlutterMethodChannel?
  7. init(channell:FlutterMethodChannel) {
  8. self.channell = channell;
  9. }
  10. public static func register(with registrar: FlutterPluginRegistrar) {
  11. let channel = FlutterMethodChannel(name: "flutterzip", binaryMessenger: registrar.messenger())
  12. let instance = SwiftFlutterzipPlugin.init(channell:channel);
  13. registrar.addMethodCallDelegate(instance, channel: channel)
  14. }
  15. public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
  16. result("iOS " + UIDevice.current.systemVersion)
  17. if(call.method=="unpack"){
  18. let arguments = call.arguments as! Dictionary<String, AnyObject>
  19. let outPath = arguments["outPath"] as! String
  20. let unzipPath = arguments["unzipPath"] as! String
  21. SSZipArchive.unzipFile(atPath: unzipPath, toDestination: outPath,delegate: self);
  22. }
  23. }
  24. public func zipArchiveProgressEvent(_ loaded: UInt64, total: UInt64) {
  25. var someDict:[String:UInt64] = ["total":total, "percent":loaded]
  26. channell?.invokeMethod("process", arguments:someDict)
  27. }
  28. }