Linux + iPhone Continuity / iMessage / SMS
turns out share ext cant bonjour. Just IP+port directly??
Zack Bartel01f49b35ac9c
diff --git a/apple/Tether/ViewModels/TetherViewModel.swift b/apple/Tether/ViewModels/TetherViewModel.swiftindex e8e4fa7..e238e54 100644--- a/apple/Tether/ViewModels/TetherViewModel.swift+++ b/apple/Tether/ViewModels/TetherViewModel.swift@@ -383,6 +383,9 @@ final class TetherViewModel {self.pendingReconnectTask = nilself.autoConnectingFingerprint = nilself.certificateManager.lastConnectedFingerprint = self.connection.serverFingerprint+ if let endpoint = self.connection.resolvedEndpoint {+ ShareSender.persistLastEndpoint(host: endpoint.host, port: endpoint.port)+ }self.handleConnected() // TODO: isInboundcase .disconnected:self.autoConnectingFingerprint = nildiff --git a/apple/TetherFramework/Sources/TetherFramework/ShareSender.swift b/apple/TetherFramework/Sources/TetherFramework/ShareSender.swiftindex 050cfc6..453b525 100644--- a/apple/TetherFramework/Sources/TetherFramework/ShareSender.swift+++ b/apple/TetherFramework/Sources/TetherFramework/ShareSender.swift@@ -51,6 +51,8 @@ public enum ShareSenderError: LocalizedError {public actor ShareSender {// Keys for the last-known Bonjour service name, stored in shared UserDefaults.private static let lastServiceNameKey = "TetherLastServiceName"+ private static let lastHostKey = "TetherLastHost"+ private static let lastPortKey = "TetherLastPort"private static let serviceType = "_tether._tcp"private static let serviceDomain = "local."@@ -79,20 +81,25 @@ public actor ShareSender {return .failure(ShareSenderError.noKnownHost)}- // 3. Resolve endpoint — use the last-known service name stored by the main app+ // 3. Resolve endpoint — prefer direct IP/Port bypass to avoid Local Network Privacy limits in the extensionlet sharedDefaults = UserDefaults(suiteName: CertificateManager.appGroupID) ?? .standard- guard let serviceName = sharedDefaults.string(forKey: lastServiceNameKey),- !serviceName.isEmpty else {+ let endpoint: NWEndpoint++ if let hostStr = sharedDefaults.string(forKey: lastHostKey), !hostStr.isEmpty,+ let portInt = sharedDefaults.object(forKey: lastPortKey) as? Int, portInt > 0,+ let port = NWEndpoint.Port(rawValue: UInt16(portInt)) {+ endpoint = NWEndpoint.hostPort(host: .init(hostStr), port: port)+ } else if let serviceName = sharedDefaults.string(forKey: lastServiceNameKey), !serviceName.isEmpty {+ endpoint = NWEndpoint.service(+ name: serviceName,+ type: serviceType,+ domain: serviceDomain,+ interface: nil+ )+ } else {return .failure(ShareSenderError.noKnownHost)}- let endpoint = NWEndpoint.service(- name: serviceName,- type: serviceType,- domain: serviceDomain,- interface: nil- )-// 4. Connectlet connection = TetherConnection()do {@@ -225,4 +232,12 @@ extension ShareSender {let sharedDefaults = UserDefaults(suiteName: CertificateManager.appGroupID) ?? .standardsharedDefaults.set(name, forKey: lastServiceNameKey)}++ /// Called by the main app once the connection is established to cache the+ /// direct IP and Port, allowing the Share Extension to bypass Bonjour entirely.+ public static func persistLastEndpoint(host: String, port: UInt16) {+ let sharedDefaults = UserDefaults(suiteName: CertificateManager.appGroupID) ?? .standard+ sharedDefaults.set(host, forKey: lastHostKey)+ sharedDefaults.set(Int(port), forKey: lastPortKey)+ }}diff --git a/apple/TetherFramework/Sources/TetherFramework/TetherConnection.swift b/apple/TetherFramework/Sources/TetherFramework/TetherConnection.swiftindex 079eadd..17d192d 100644--- a/apple/TetherFramework/Sources/TetherFramework/TetherConnection.swift+++ b/apple/TetherFramework/Sources/TetherFramework/TetherConnection.swift@@ -32,6 +32,15 @@ public final class TetherConnection {// The server's TLS certificate fingerprint, captured during handshake.public private(set) var serverFingerprint: String = ""+ // The actual resolved IP and Port of the active connection, if available.+ public var resolvedEndpoint: (host: String, port: UInt16)? {+ guard let endpoint = connection?.currentPath?.remoteEndpoint else { return nil }+ if case .hostPort(let host, let port) = endpoint {+ return ("\(host)", port.rawValue)+ }+ return nil+ }+private var connection: NWConnection?private var receiveBuffer = Data()