Loading files
59e2a9d01This file is pinned to the selected release. Download the original to open it in your design tool.
import Flutter
import UIKit
@main
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
DeviceNameChannel.register(with: engineBridge.pluginRegistry)
}
}
/// `harness/device_name` — what this phone is called, for the far side's "took control" banner
/// (Dart: `lib/core/device_name.dart`). `name` is the user's own name for the device where iOS still
/// hands it out (before iOS 16, or with Apple's user-assigned-device-name entitlement); otherwise it
/// is the generic "iPhone" and Dart falls back to the model, read off the hardware code.
enum DeviceNameChannel {
static func register(with registry: FlutterPluginRegistry) {
guard let messenger = registry.registrar(forPlugin: "HarnessDeviceName")?.messenger() else { return }
let channel = FlutterMethodChannel(name: "harness/device_name", binaryMessenger: messenger)
channel.setMethodCallHandler { call, result in
guard call.method == "describe" else { result(FlutterMethodNotImplemented); return }
result([
"name": UIDevice.current.name,
"model": UIDevice.current.model,
"modelCode": modelCode(),
"manufacturer": "Apple",
])
}
}
/// "iPhone16,1" — the hardware identifier; on the simulator, the device it is pretending to be.
private static func modelCode() -> String {
if let simulated = ProcessInfo.processInfo.environment["SIMULATOR_MODEL_IDENTIFIER"], !simulated.isEmpty {
return simulated
}
var systemInfo = utsname()
uname(&systemInfo)
return withUnsafePointer(to: &systemInfo.machine) {
$0.withMemoryRebound(to: CChar.self, capacity: 1) { String(validatingCString: $0) ?? "" }
}
}
}