1. 升级依赖版本
2. 解决运行项目警告日志问题 3. 优化代码
This commit is contained in:
@@ -15,5 +15,8 @@ import UIKit
|
||||
if let registrar = engineBridge.pluginRegistry.registrar(forPlugin: "RecordingPlugin") {
|
||||
RecordingPlugin.register(with: registrar)
|
||||
}
|
||||
if let registrar = engineBridge.pluginRegistry.registrar(forPlugin: "PlatformInfoPlugin") {
|
||||
PlatformInfoPlugin.register(with: registrar)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
71
ios/Runner/PlatformInfoPlugin.swift
Normal file
71
ios/Runner/PlatformInfoPlugin.swift
Normal file
@@ -0,0 +1,71 @@
|
||||
import Flutter
|
||||
import UIKit
|
||||
|
||||
final class PlatformInfoPlugin: NSObject, FlutterPlugin {
|
||||
static func register(with registrar: FlutterPluginRegistrar) {
|
||||
let channel = FlutterMethodChannel(
|
||||
name: "com.gdfw.fxjk/platform_info",
|
||||
binaryMessenger: registrar.messenger()
|
||||
)
|
||||
let plugin = PlatformInfoPlugin()
|
||||
registrar.addMethodCallDelegate(plugin, channel: channel)
|
||||
}
|
||||
|
||||
func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
|
||||
switch call.method {
|
||||
case "packageInfo":
|
||||
result(packageInfoMap())
|
||||
case "deviceInfo":
|
||||
result(deviceInfoMap())
|
||||
default:
|
||||
result(FlutterMethodNotImplemented)
|
||||
}
|
||||
}
|
||||
|
||||
private func packageInfoMap() -> [String: String] {
|
||||
let bundle = Bundle.main
|
||||
return [
|
||||
"appName": displayName(bundle: bundle),
|
||||
"packageName": bundle.bundleIdentifier ?? "",
|
||||
"version": bundle.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "",
|
||||
"buildNumber": bundle.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "",
|
||||
]
|
||||
}
|
||||
|
||||
private func deviceInfoMap() -> [String: Any] {
|
||||
let device = UIDevice.current
|
||||
return [
|
||||
"platform": "ios",
|
||||
"brand": device.systemName,
|
||||
"model": machineIdentifier(),
|
||||
"systemVersion": device.systemVersion,
|
||||
"isPhysicalDevice": !isSimulator(),
|
||||
]
|
||||
}
|
||||
|
||||
private func displayName(bundle: Bundle) -> String {
|
||||
if let displayName = bundle.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String {
|
||||
return displayName
|
||||
}
|
||||
return bundle.object(forInfoDictionaryKey: "CFBundleName") as? String ?? ""
|
||||
}
|
||||
|
||||
private func isSimulator() -> Bool {
|
||||
#if targetEnvironment(simulator)
|
||||
return true
|
||||
#else
|
||||
return false
|
||||
#endif
|
||||
}
|
||||
|
||||
private func machineIdentifier() -> String {
|
||||
var systemInfo = utsname()
|
||||
uname(&systemInfo)
|
||||
let mirror = Mirror(reflecting: systemInfo.machine)
|
||||
let identifier = mirror.children.reduce(into: "") { value, element in
|
||||
guard let byte = element.value as? Int8, byte != 0 else { return }
|
||||
value.append(String(UnicodeScalar(UInt8(byte))))
|
||||
}
|
||||
return identifier
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user