diff --git a/Sources/Classes/core/View/MiniAppViewHandler.swift b/Sources/Classes/core/View/MiniAppViewHandler.swift index ee6973a0..a7861ddc 100644 --- a/Sources/Classes/core/View/MiniAppViewHandler.swift +++ b/Sources/Classes/core/View/MiniAppViewHandler.swift @@ -865,7 +865,11 @@ extension MiniAppViewHandler: MiniAppCallbackDelegate { } func didReceiveEvent(_ event: MiniAppEvent, message: String) { - let messageBody = Constants.JavaScript.eventCallback + "('\(event.rawValue)'," + "'\(message)')" + var encodedMessage = message + if event == .miniappReceiveJsonString { + encodedMessage = message.base64Encoded() ?? "" + } + let messageBody = Constants.JavaScript.eventCallback + "('\(event.rawValue)'," + "'\(encodedMessage)')" messageBodies.append(messageBody) MiniAppLogger.d(messageBody, "♨️️") webView?.evaluateJavaScript(messageBody) @@ -966,4 +970,11 @@ extension MiniAppViewHandler { self.didReceiveEvent(MiniAppEvent.miniappReceiveJsonString, message: jsonString ?? "") } } + +extension String { + func base64Encoded() -> String? { + guard let data = data(using: .nonLossyASCII) else { return "" } + return data.base64EncodedString() + } +} // swiftlint:enable file_length function_body_length