Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

vphoned: link Vision weakly, for watch guests

Maximilian Paß3143d60af59c
diff --git a/VPhoneDaemon/Daemon/GuestAPI+Input.swift b/VPhoneDaemon/Daemon/GuestAPI+Input.swift
index fab99902..6660b818 100644
--- a/VPhoneDaemon/Daemon/GuestAPI+Input.swift
+++ b/VPhoneDaemon/Daemon/GuestAPI+Input.swift
@@ -97,17 +97,27 @@ extension GuestAPI {
timeout: number(params, "timeout", default: 10),
)
case "ui.ocr":
+ try requireTextRecognition()
return try recognizeScreen(
languages: params["languages"] as? [String] ?? ["en-US"],
minConfidence: Float(number(params, "min_confidence", default: 0.3)),
)
case "ui.describe":
+ try requireTextRecognition()
return try describeScreen()
default:
return nil
}
}
+ /// IcliKit's OCR is Vision's, which watchOS does not ship: vphoned links
+ /// it weakly, so its classes are nil on a watch.
+ private static func requireTextRecognition() throws {
+ guard NSClassFromString("VNRecognizeTextRequest") != nil else {
+ throw GuestAPIError.operationFailed("Text recognition needs Vision, which this guest does not have")
+ }
+ }
+
private static func selector(_ params: [String: Any]) throws -> ElementSelector {
try ElementSelector(
text: optionalString(params, "text"),
diff --git a/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.pbxproj b/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.pbxproj
index 6fd9a05d..abb20a7e 100644
--- a/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.pbxproj
+++ b/VPhoneDaemon/VPhoneDaemon.xcodeproj/project.pbxproj
@@ -259,7 +259,11 @@
HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/Native/Include";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LIBRARY_SEARCH_PATHS = "$(SRCROOT)/../.build/XcodeSignGuest-$(CONFIGURATION)/Build/Products/$(CONFIGURATION)-iphoneos";
- OTHER_LDFLAGS = "-lVPhoneSign";
+ OTHER_LDFLAGS = (
+ "-lVPhoneSign",
+ "-weak_framework",
+ Vision,
+ );
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_INCLUDE_PATHS = "$(SRCROOT)/../.build/XcodeSignGuest-$(CONFIGURATION)/Build/Products/$(CONFIGURATION)-iphoneos";
@@ -276,7 +280,11 @@
HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/Native/Include";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LIBRARY_SEARCH_PATHS = "$(SRCROOT)/../.build/XcodeSignGuest-$(CONFIGURATION)/Build/Products/$(CONFIGURATION)-iphoneos";
- OTHER_LDFLAGS = "-lVPhoneSign";
+ OTHER_LDFLAGS = (
+ "-lVPhoneSign",
+ "-weak_framework",
+ Vision,
+ );
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_INCLUDE_PATHS = "$(SRCROOT)/../.build/XcodeSignGuest-$(CONFIGURATION)/Build/Products/$(CONFIGURATION)-iphoneos";