From f89e3c06dbd0b5540c2baca1fe9cccc4cb0e200e Mon Sep 17 00:00:00 2001 From: heiha <01sr@outlook.com> Date: Fri, 26 Apr 2024 15:04:56 +0800 Subject: [PATCH] fix: support unascii character for TxtRecord on darwin --- .../darwin/Classes/Broadcast/BonsoirServiceBroadcast.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/bonsoir_darwin/darwin/Classes/Broadcast/BonsoirServiceBroadcast.swift b/packages/bonsoir_darwin/darwin/Classes/Broadcast/BonsoirServiceBroadcast.swift index c73137d7..17064918 100644 --- a/packages/bonsoir_darwin/darwin/Classes/Broadcast/BonsoirServiceBroadcast.swift +++ b/packages/bonsoir_darwin/darwin/Classes/Broadcast/BonsoirServiceBroadcast.swift @@ -26,7 +26,8 @@ class BonsoirServiceBroadcast: BonsoirAction { var txtRecord = TXTRecordRef() TXTRecordCreate(&txtRecord, 0, nil) for (key, value) in service.attributes { - TXTRecordSetValue(&txtRecord, key, UInt8(value.count), value) + guard let valueData = value.data(using: .utf8) else { continue } + TXTRecordSetValue(&txtRecord, key, UInt8(valueData.count), [UInt8](valueData)) } let error = DNSServiceRegister(&sdRef, 0, 0, service.name, service.type, "local.", service.host, CFSwapInt16HostToBig(UInt16(service.port)), TXTRecordGetLength(&txtRecord), TXTRecordGetBytesPtr(&txtRecord), BonsoirServiceBroadcast.registerCallback as DNSServiceRegisterReply, Unmanaged.passUnretained(self).toOpaque()) if error == kDNSServiceErr_NoError {