Skip to content

Commit

Permalink
Merge branch 'master' into feat/MINI-6313
Browse files Browse the repository at this point in the history
  • Loading branch information
rleojoseph authored Nov 5, 2023
2 parents 64feb30 + 2fccc8b commit c179e14
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Sources/Classes/core/View/MiniAppViewHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit c179e14

Please sign in to comment.