2021-09-29 23:57:09 +00:00
|
|
|
import UIKit
|
|
|
|
import Flutter
|
2021-11-11 03:00:38 +00:00
|
|
|
import Mobile
|
2022-05-14 13:45:00 +00:00
|
|
|
import LocalAuthentication
|
2021-09-29 23:57:09 +00:00
|
|
|
|
|
|
|
@UIApplicationMain
|
|
|
|
@objc class AppDelegate: FlutterAppDelegate {
|
2021-12-10 11:38:17 +00:00
|
|
|
|
2021-09-29 23:57:09 +00:00
|
|
|
override func application(
|
|
|
|
_ application: UIApplication,
|
|
|
|
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
|
|
|
) -> Bool {
|
|
|
|
|
|
|
|
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
|
2022-10-14 17:54:50 +00:00
|
|
|
let applicationSupportsPath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true)[0]
|
|
|
|
|
|
|
|
MobileMigration(documentsPath, applicationSupportsPath)
|
|
|
|
MobileInitApplication(applicationSupportsPath)
|
|
|
|
|
2021-09-29 23:57:09 +00:00
|
|
|
|
|
|
|
let controller = self.window.rootViewController as! FlutterViewController
|
|
|
|
let channel = FlutterMethodChannel.init(name: "method", binaryMessenger: controller as! FlutterBinaryMessenger)
|
|
|
|
|
|
|
|
channel.setMethodCallHandler { (call, result) in
|
|
|
|
Thread {
|
|
|
|
if call.method == "flatInvoke" {
|
|
|
|
if let args = call.arguments as? Dictionary<String, Any>,
|
|
|
|
let method = args["method"] as? String,
|
|
|
|
let params = args["params"] as? String{
|
|
|
|
var error: NSError?
|
|
|
|
let data = MobileFlatInvoke(method, params, &error)
|
|
|
|
if error != nil {
|
|
|
|
result(FlutterError(code: "", message: error?.localizedDescription, details: ""))
|
|
|
|
}else{
|
|
|
|
result(data)
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
result(FlutterError(code: "", message: "params error", details: ""))
|
|
|
|
}
|
|
|
|
}
|
2022-05-14 13:45:00 +00:00
|
|
|
else if call.method == "verifyAuthentication"{
|
|
|
|
let context = LAContext()
|
|
|
|
let can = context.canEvaluatePolicy(.deviceOwnerAuthentication, error: nil)
|
|
|
|
guard can == true else {
|
|
|
|
result(false)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
context.evaluatePolicy(.deviceOwnerAuthentication, localizedReason: "身份验证") { (success, error) in
|
|
|
|
result(success)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-09-29 23:57:09 +00:00
|
|
|
else if call.method == "iosSaveFileToImage"{
|
|
|
|
if let args = call.arguments as? Dictionary<String, Any>,
|
|
|
|
let path = args["path"] as? String{
|
|
|
|
|
|
|
|
do {
|
|
|
|
let fileURL: URL = URL(fileURLWithPath: path)
|
|
|
|
let imageData = try Data(contentsOf: fileURL)
|
|
|
|
|
|
|
|
if let uiImage = UIImage(data: imageData) {
|
|
|
|
UIImageWriteToSavedPhotosAlbum(uiImage, nil, nil, nil)
|
|
|
|
result("OK")
|
|
|
|
}else{
|
|
|
|
result(FlutterError(code: "", message: "Error loading image ", details: ""))
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
result(FlutterError(code: "", message: "Error loading image : \(error)", details: ""))
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
result(FlutterError(code: "", message: "params error", details: ""))
|
|
|
|
}
|
|
|
|
}
|
2022-10-14 17:54:50 +00:00
|
|
|
else if call.method == "iosGetDocumentDir" {
|
|
|
|
result(documentsPath)
|
|
|
|
} else {
|
2021-09-29 23:57:09 +00:00
|
|
|
result(FlutterMethodNotImplemented)
|
|
|
|
}
|
|
|
|
}.start()
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
let eventChannel = FlutterEventChannel.init(name: "flatEvent", binaryMessenger: controller as! FlutterBinaryMessenger)
|
|
|
|
|
|
|
|
class EventChannelHandler:NSObject, FlutterStreamHandler {
|
|
|
|
func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
|
|
|
|
objc_sync_enter(mutex)
|
|
|
|
sink = events
|
|
|
|
objc_sync_exit(mutex)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func onCancel(withArguments arguments: Any?) -> FlutterError? {
|
|
|
|
objc_sync_enter(mutex)
|
|
|
|
sink = nil
|
|
|
|
objc_sync_exit(mutex)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class EventNotifyHandler:NSObject, MobileEventNotifyHandlerProtocol {
|
|
|
|
func onNotify(_ message: String?) {
|
|
|
|
objc_sync_enter(mutex)
|
|
|
|
if sink != nil {
|
|
|
|
sink?(message)
|
|
|
|
}
|
|
|
|
objc_sync_exit(mutex)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
eventChannel.setStreamHandler(EventChannelHandler.init())
|
|
|
|
MobileEventNotify(EventNotifyHandler.init())
|
|
|
|
|
|
|
|
//
|
|
|
|
GeneratedPluginRegistrant.register(with: self)
|
|
|
|
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var sink : FlutterEventSink?
|
|
|
|
let mutex = NSObject.init()
|
|
|
|
|