Skip to content

Commit

Permalink
edit url configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
QSD_faris committed May 22, 2024
1 parent e6c338e commit 67bcc9b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Sources/Deskpro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,23 @@ import UIKit
/// - Returns: A [PresentBuilder](x-source-tag://PresentBuilder) instance to start building presentation paths.
///
@objc public final func present() -> PresentBuilder {
let url = messengerConfig.appUrl//.appending(messengerConfig.appId)
//return PresentBuilder(url: url, containingViewController: containingViewController)
return PresentBuilder(url: url, appId: messengerConfig.appId, coordinator: coordinator)
let url = buildUrl(baseUrl: messengerConfig.appUrl, appId: messengerConfig.appId)
return PresentBuilder(url: url ?? "", appId: messengerConfig.appId, coordinator: coordinator)
}

func buildUrl(baseUrl: String, appId: String) -> String? {
let platformData = ["platform": "IOS"]

guard let platformJsonData = try? JSONSerialization.data(withJSONObject: platformData, options: []),
let platformJsonString = String(data: platformJsonData, encoding: .utf8),
let encodedPlatform = platformJsonString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
return nil
}

let formattedBaseUrl = baseUrl.trimmingCharacters(in: CharacterSet(charactersIn: "/"))
let formattedAppId = "/" + appId.trimmingCharacters(in: CharacterSet(charactersIn: "/"))

return "\(formattedBaseUrl)\(formattedAppId)/\(encodedPlatform)"
}

/// Closes the chat view presented by the DeskPro SDK.
Expand Down

0 comments on commit 67bcc9b

Please sign in to comment.