50 lines
1.6 KiB
Swift
50 lines
1.6 KiB
Swift
import Flutter
|
|
import UIKit
|
|
|
|
public class AppUpgradePlugin: NSObject, FlutterPlugin {
|
|
public static func register(with registrar: FlutterPluginRegistrar) {
|
|
let channel = FlutterMethodChannel(name: "yx_app_upgrade_flutter", binaryMessenger: registrar.messenger())
|
|
let instance = AppUpgradePlugin()
|
|
registrar.addMethodCallDelegate(instance, channel: channel)
|
|
}
|
|
|
|
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
|
switch call.method {
|
|
case "getPlatformVersion":
|
|
result(
|
|
"iOS " + UIDevice.current.systemVersion
|
|
)
|
|
case "goToAppStore":
|
|
let args = call.arguments as? [String: Any]
|
|
let url = args?["url"] as? String
|
|
if let url = url {
|
|
if let appUrl = URL(string: url) {
|
|
UIApplication.shared.open(appUrl, options: [:], completionHandler: nil)
|
|
result(true)
|
|
} else {
|
|
result(false)
|
|
}
|
|
} else {
|
|
result(false)
|
|
}
|
|
case "getDownloadPath":
|
|
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
|
|
result(paths.first?.path)
|
|
case "checkApkExists":
|
|
// Not applicable for iOS
|
|
result(false)
|
|
case "goToMarket":
|
|
// For iOS, goToMarket is the same as goToAppStore
|
|
let args = call.arguments as? [String: Any]
|
|
let url = args?["url"] as? String
|
|
if let url = url, let appUrl = URL(string: url) {
|
|
UIApplication.shared.open(appUrl, options: [:], completionHandler: nil)
|
|
result(true)
|
|
} else {
|
|
result(false)
|
|
}
|
|
default:
|
|
result(FlutterMethodNotImplemented)
|
|
}
|
|
}
|
|
} |