Fix: iPad Name too long for QuickShare

This commit is contained in:
Leon Böttger committed 2025-08-18 15:14:26 +02:00
1 parent cecffa1aaa
commit 1eebce1caa
2 files changed
+21 -2

No files matched your search

@@ -48,7 +48,7 @@ public class NearbyConnectionManager: NSObject, NetServiceDelegate, InboundNearb
#if os(macOS)
self.deviceInfo = EndpointInfo(name: Host.current().localizedName ?? "Mac", deviceType: .computer)
#else
self.deviceInfo = EndpointInfo(name: UIDevice.current.marketingName, deviceType: .phone)
self.deviceInfo = EndpointInfo(name: UIDevice.current.marketingName.withoutBracketedContent, deviceType: .phone)
#endif
tcpListener = try! NWListener(using: NWParameters(tls: .none))
+20 -1
View File
@@ -64,7 +64,7 @@ extension Data {
}
extension SymmetricKey{
extension SymmetricKey {
func data() -> Data{
return withUnsafeBytes({return Data(bytes: $0.baseAddress!, count: $0.count)})
}
@@ -88,6 +88,25 @@ extension String {
}
return data
}
var withoutBracketedContent: String {
let input = self
// Replace any (...) including content inside, multiple times
let pattern = #"\([^)]*\)"#
let regex = try! NSRegularExpression(pattern: pattern, options: [])
// Remove all bracketed parts
let range = NSRange(location: 0, length: input.utf16.count)
var result = regex.stringByReplacingMatches(in: input, options: [], range: range, withTemplate: "")
// Remove extra spaces left behind
result = result.replacingOccurrences(of: " ", with: " ") // collapse double spaces
result = result.trimmingCharacters(in: .whitespacesAndNewlines)
return result
}
}