From 5848b4e8e9fde1e0d895238cafdb57ed20be4c07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillem=20C=C3=B3rdoba?= Date: Thu, 14 Dec 2023 13:25:28 +0100 Subject: [PATCH] Fixed channel deserialisation in iOS (#8386) * Fixed channel * Change file --- .changes/fix-ios-channel.md | 5 +++++ core/tauri/mobile/ios-api/Sources/Tauri/Channel.swift | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .changes/fix-ios-channel.md diff --git a/.changes/fix-ios-channel.md b/.changes/fix-ios-channel.md new file mode 100644 index 000000000..a1bf8bf7a --- /dev/null +++ b/.changes/fix-ios-channel.md @@ -0,0 +1,5 @@ +--- +"tauri": 'patch:enhance' +--- + +Fixed the deserialisation of a `Channel` in iOS. \ No newline at end of file diff --git a/core/tauri/mobile/ios-api/Sources/Tauri/Channel.swift b/core/tauri/mobile/ios-api/Sources/Tauri/Channel.swift index 798104c7a..bb448bf9b 100644 --- a/core/tauri/mobile/ios-api/Sources/Tauri/Channel.swift +++ b/core/tauri/mobile/ios-api/Sources/Tauri/Channel.swift @@ -9,7 +9,7 @@ let channelDataKey = CodingUserInfoKey(rawValue: "sendChannelData")! public class Channel: Decodable { public let id: UInt64 - let handler: (String) -> Void + let handler: (UInt64, String) -> Void public required init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() @@ -30,7 +30,7 @@ public class Channel: Decodable { ) } - guard let handler = decoder.userInfo[channelDataKey] as? (String) -> Void else { + guard let handler = decoder.userInfo[channelDataKey] as? (UInt64, String) -> Void else { throw DecodingError.dataCorruptedError( in: container, debugDescription: "missing userInfo for Channel handler. This is a Tauri issue" @@ -54,12 +54,12 @@ public class Channel: Decodable { } public func send(_ data: JsonValue) { - handler(serialize(data)) + handler(id, serialize(data)) } public func send(_ data: T) throws { let json = try JSONEncoder().encode(data) - handler(String(decoding: json, as: UTF8.self)) + handler(id, String(decoding: json, as: UTF8.self)) } }