[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"initial-data":3,"kb:search:disabled":33,"kb:sectionPath:null:null:es":36,"kb:categories:1:es":37,"kb:brandArticles:1:0:es":38,"kb:articleDetails:120:es":45},[4,14],{"theme":5,"assets":11},{"color-primary":6,"color-page-bg":7,"color-page-bg-dark":8,"color-content-bg":7,"color-content-bg-hover":9,"color-text-default":10},"#e51728","#ffffff","#121212","#f6f9fc","#0a2540",{"logo":12,"favicon":13},"\u002Fknowledge-base\u002Fpleased-logo.svg","\u002Fknowledge-base\u002Fpleased-favicon.svg",[15],{"name":16,"code":17,"url":17,"displayOrder":18,"isActive":19,"inboundEmailDomains":20,"outboundEmailDomain":20,"publishSettings":21,"id":18},"Pleased","pleased",1,true,"@pleased.com",{"KB":22,"CHATBOT":29},{"publishedLanguages":23,"defaultLanguage":28},[24],{"name":25,"nameLocal":26,"locale":27},"English*","English","en",{"name":25,"nameLocal":26,"locale":27},{"publishedLanguages":30,"defaultLanguage":32},[31],{"name":25,"nameLocal":26,"locale":27},null,{"data":34,"total":35},[],0,[],[],{"content":39,"number":35,"size":40,"totalElements":35,"pageable":41,"last":19,"totalPages":35,"sort":44,"first":19,"numberOfElements":35,"empty":19},[],10,{"sort":42,"offset":35,"pageNumber":35,"pageSize":40,"paged":19,"unpaged":43},{"sorted":19,"empty":43,"unsorted":43},false,{"sorted":19,"empty":43,"unsorted":43},{"article":46,"sections":56,"category":61,"relatedArticles":64,"relatedTagsArticles":99},{"id":47,"brandId":18,"sectionId":48,"categoryId":32,"title":49,"body":50,"keywords":32,"position":47,"isCommentDisabled":32,"isDraft":43,"isPromoted":43,"upvotes":32,"downvotes":32,"isActive":19,"language":27,"englishVersion":19,"createdAt":51,"createdBy":52,"updatedAt":53,"updatedBy":52,"tags":32,"includeForAi":19,"authorName":54,"slug":55},120,9,"Integrating the Chatbot into your iOS application","\u003Cp>You can show the Pleased Chat Widget inside your iOS app. Your app opens a screen with a \u003Ccode>WKWebView\u003C\u002Fcode>, and the \u003Ccode>WKWebView\u003C\u002Fcode> loads a page that Pleased hosts for you. You do not need a website of your own.\u003C\u002Fp>\u003Cp>This article is for the iOS developer adding the widget. It covers the chat itself, signing in your users, file attachments and voice calls.\u003C\u002Fp>\u003Chr>\u003Ch2>Before you begin\u003C\u002Fh2>\u003Cul>\u003Cli>An Xcode project with deployment target iOS 15 or higher. The integration uses an iOS 15 WebKit API and does not compile on older deployment targets. You do not need CocoaPods or other packages.\u003C\u002Fli>\u003Cli>A Chat Widget created in Pleased. See \u003Cem>Install the Pleased Chat Widget on your website\u003C\u002Fem> for how to create one.\u003C\u002Fli>\u003Cli>Your client ID and widget ID from the generated Chat Widget code: \u003Ccode>data-pls-client-id\u003C\u002Fcode> and \u003Ccode>data-pls-widget-id\u003C\u002Fcode>.\u003C\u002Fli>\u003C\u002Ful>\u003Cblockquote>Important: Use the IDs from the code generated for your Chat Widget in Pleased. Do not copy the example values from this article.\u003C\u002Fblockquote>\u003Chr>\u003Ch2>Step 1: Add the usage descriptions\u003C\u002Fh2>\u003Cp>Add both keys to your app’s \u003Ccode>Info.plist\u003C\u002Fcode> (or the target Info tab in Xcode):\u003C\u002Fp>\u003Cpre class=\"ql-syntax\" spellcheck=\"false\">&lt;key&gt;NSMicrophoneUsageDescription&lt;\u002Fkey&gt;\n&lt;string&gt;We use the microphone for voice support in the chat.&lt;\u002Fstring&gt;\n&lt;key&gt;NSCameraUsageDescription&lt;\u002Fkey&gt;\n&lt;string&gt;We use the camera so you can send a photo in the chat.&lt;\u002Fstring&gt;\n\u003C\u002Fpre>\u003Cp>iOS shows these on its permission prompts.\u003C\u002Fp>\u003Cblockquote>Important: \u003Ccode>NSCameraUsageDescription\u003C\u002Fcode> is required for attachments. The chat’s attach control accepts images, so on a real iPhone the system picker offers Take Photo. WebKit shows that option without checking the plist first; tapping it without \u003Ccode>NSCameraUsageDescription\u003C\u002Fcode> crashes the app. The Simulator has no camera, so you will not see this there.\u003C\u002Fblockquote>\u003Cp>Without \u003Ccode>NSMicrophoneUsageDescription\u003C\u002Fcode>, microphone requests are refused and no prompt appears (WebKit checks for the key). Skip the microphone key only if you will never use voice calls.\u003C\u002Fp>\u003Chr>\u003Ch2>Step 2: Add the two Swift files\u003C\u002Fh2>\u003Cp>Copy both files into your Xcode project as they are.\u003C\u002Fp>\u003Ch3>PleasedWebViewSetup.swift\u003C\u002Fh3>\u003Cp>Configures the \u003Ccode>WKWebView\u003C\u002Fcode>, answers microphone requests (iOS 15+), and opens off-site links in Safari.\u003C\u002Fp>\u003Cpre class=\"ql-syntax\" spellcheck=\"false\">import Foundation\nimport SafariServices\nimport UIKit\nimport WebKit\n\n\u002F\u002F\u002F WebView setup for the Pleased chatbot. Copy this file as-is.\nfinal class PleasedWebViewSetup: NSObject {\n    static let defaultWidgetOrigins: Set&lt;String&gt; = [\"https:\u002F\u002Fcdn.pleased.com\"]\n\n    private weak var webView: WKWebView?\n    private let widgetOrigins: Set&lt;String&gt;\n    private var pinnedUrl: String?\n\n    init(webView: WKWebView, widgetOrigins: Set&lt;String&gt; = PleasedWebViewSetup.defaultWidgetOrigins) {\n        self.webView = webView\n        self.widgetOrigins = widgetOrigins\n        super.init()\n    }\n\n    \u002F\u002F\u002F Apply before `WKWebView(frame:configuration:)`. Playback options are read at construction.\n    static func applyMediaPlaybackPolicy(to configuration: WKWebViewConfiguration) {\n        configuration.allowsInlineMediaPlayback = true\n        if #available(iOS 10.0, *) {\n            configuration.mediaTypesRequiringUserActionForPlayback = []\n        }\n        if #available(iOS 16.4, *) {\n            configuration.preferences.isElementFullscreenEnabled = true\n        }\n    }\n\n    func configure() {\n        guard let webView else { return }\n        #if DEBUG\n        if #available(iOS 16.4, *) {\n            webView.isInspectable = true\n        }\n        #endif\n\n        webView.navigationDelegate = self\n        webView.uiDelegate = self\n    }\n\n    static func origin(of urlString: String?) -&gt; String? {\n        guard let urlString,\n              let url = URL(string: urlString),\n              let scheme = url.scheme,\n              let host = url.host\n        else { return nil }\n        if let port = url.port {\n            return \"\\(scheme):\u002F\u002F\\(host):\\(port)\"\n        }\n        return \"\\(scheme):\u002F\u002F\\(host)\"\n    }\n\n    private func withoutFragment(_ url: String) -&gt; String {\n        url.split(separator: \"#\", maxSplits: 1).first.map(String.init) ?? url\n    }\n\n    private func leaveWebView(_ url: String) {\n        guard let url = URL(string: url) else { return }\n        DispatchQueue.main.async {\n            UIApplication.shared.open(url)\n        }\n    }\n\n    func answerMediaCapture(\n        origin: WKSecurityOrigin,\n        type: WKMediaCaptureType,\n        decisionHandler: @escaping (WKPermissionDecision) -&gt; Void\n    ) {\n        guard type == .microphone else {\n            decisionHandler(.deny)\n            return\n        }\n        let asking = Self.origin(from: origin)\n        let pinnedOrigin = Self.origin(of: pinnedUrl)\n        if asking == nil || (asking != pinnedOrigin &amp;&amp; !widgetOrigins.contains(asking ?? \"\")) {\n            decisionHandler(.deny)\n            return\n        }\n        decisionHandler(.grant)\n    }\n\n    static func origin(from securityOrigin: WKSecurityOrigin) -&gt; String? {\n        let host = securityOrigin.host\n        if host.isEmpty { return nil }\n        if securityOrigin.port == 0 {\n            return \"\\(securityOrigin.protocol):\u002F\u002F\\(host)\"\n        }\n        return \"\\(securityOrigin.protocol):\u002F\u002F\\(host):\\(securityOrigin.port)\"\n    }\n}\n\nextension PleasedWebViewSetup: WKNavigationDelegate {\n    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {\n        if pinnedUrl == nil {\n            pinnedUrl = withoutFragment(webView.url?.absoluteString ?? \"\")\n        }\n    }\n\n    func webView(\n        _ webView: WKWebView,\n        decidePolicyFor navigationAction: WKNavigationAction,\n        decisionHandler: @escaping (WKNavigationActionPolicy) -&gt; Void\n    ) {\n        if navigationAction.targetFrame == nil {\n            if let target = navigationAction.request.url?.absoluteString {\n                leaveWebView(target)\n            }\n            decisionHandler(.cancel)\n            return\n        }\n        guard navigationAction.targetFrame?.isMainFrame == true else {\n            decisionHandler(.allow)\n            return\n        }\n        let pinned = pinnedUrl\n        guard let pinned, let target = navigationAction.request.url?.absoluteString else {\n            decisionHandler(.allow)\n            return\n        }\n        if withoutFragment(target) == pinned {\n            decisionHandler(.allow)\n            return\n        }\n        leaveWebView(target)\n        decisionHandler(.cancel)\n    }\n\n    func webView(\n        _ webView: WKWebView,\n        decidePolicyFor navigationResponse: WKNavigationResponse,\n        decisionHandler: @escaping (WKNavigationResponsePolicy) -&gt; Void\n    ) {\n        guard navigationResponse.isForMainFrame else {\n            decisionHandler(.allow)\n            return\n        }\n        let pinned = pinnedUrl\n        guard let pinned, let target = navigationResponse.response.url?.absoluteString else {\n            decisionHandler(.allow)\n            return\n        }\n        if withoutFragment(target) == pinned {\n            decisionHandler(.allow)\n            return\n        }\n        leaveWebView(target)\n        decisionHandler(.cancel)\n    }\n}\n\n@available(iOS 15.0, *)\nextension PleasedWebViewSetup: WKUIDelegate {\n    func webView(\n        _ webView: WKWebView,\n        requestMediaCapturePermissionFor origin: WKSecurityOrigin,\n        initiatedByFrame frame: WKFrameInfo,\n        type: WKMediaCaptureType,\n        decisionHandler: @escaping (WKPermissionDecision) -&gt; Void\n    ) {\n        answerMediaCapture(origin: origin, type: type, decisionHandler: decisionHandler)\n    }\n}\n\u003C\u002Fpre>\u003Ch3>PleasedBridge.swift\u003C\u002Fh3>\u003Cp>Lets your app talk to the widget: visitor token, open\u002Fclose chat, events.\u003C\u002Fp>\u003Cpre class=\"ql-syntax\" spellcheck=\"false\">import Foundation\nimport WebKit\n\n\u002F\u002F\u002F Drives the Pleased loader running inside a WKWebView. Copy this file as-is.\nfinal class PleasedBridge: NSObject {\n    typealias CallbackHandler = (_ payloadJson: String?, _ respond: Responder) -&gt; Void\n\n    protocol Responder: AnyObject {\n        func resolve(valueJson: String?)\n        func reject(error: String)\n    }\n\n    var onLoaderReady: (() -&gt; Void)?\n    var onLog: ((String) -&gt; Void)?\n\n    private weak var webView: WKWebView?\n    private weak var userContentController: WKUserContentController?\n    private let lock = NSLock()\n    private var handlers: [String: CallbackHandler] = [:]\n\n    init(configuration: WKWebViewConfiguration) {\n        super.init()\n        let controller = configuration.userContentController\n        userContentController = controller\n        controller.add(self, name: \"pleasedNative\")\n    }\n\n    func bind(webView: WKWebView) {\n        self.webView = webView\n    }\n\n    deinit {\n        userContentController?.removeScriptMessageHandler(forName: \"pleasedNative\")\n    }\n\n    func invoke(_ command: String, payloadJson: String? = nil, onResult: ((String) -&gt; Void)? = nil) {\n        if let payloadJson, !payloadJson.isEmpty {\n            let opts: JSONSerialization.ReadingOptions = [.fragmentsAllowed]\n            if (try? JSONSerialization.jsonObject(with: Data(payloadJson.utf8), options: opts)) == nil {\n                let error = #\"{\"ok\":false,\"error\":\"payloadJson is not valid JSON\"}\"#\n                dispatchMain { onResult?(error) }\n                return\n            }\n        }\n        let payloadPart = payloadJson.map { jsonQuote($0) } ?? \"null\"\n        let js = \"window.__plInvoke(\\(jsonQuote(command)), \\(payloadPart))\"\n        eval(js, onResult: onResult)\n    }\n\n    func registerCallback(type: String, name: String, handler: @escaping CallbackHandler) {\n        lock.lock()\n        handlers[\"\\(type)|\\(name)\"] = handler\n        lock.unlock()\n        eval(\"window.__plAddCallback(\\(jsonQuote(type)), \\(jsonQuote(name)))\")\n    }\n\n    func removeCallback(type: String, name: String) {\n        lock.lock()\n        handlers.removeValue(forKey: \"\\(type)|\\(name)\")\n        lock.unlock()\n        eval(\"window.__plRemoveCallback(\\(jsonQuote(type)), \\(jsonQuote(name)))\")\n    }\n\n    private func eval(_ js: String, onResult: ((String) -&gt; Void)? = nil) {\n        dispatchMain {\n            guard let webView = self.webView else {\n                onResult?(\"null\")\n                return\n            }\n            webView.evaluateJavaScript(js) { value, error in\n                if error != nil, onResult != nil {\n                    onResult?(\"null\")\n                    return\n                }\n                if let onResult {\n                    onResult(Self.unwrap(value))\n                }\n            }\n        }\n    }\n\n    private func dispatchMain(_ block: @escaping () -&gt; Void) {\n        if Thread.isMainThread {\n            block()\n        } else {\n            DispatchQueue.main.async(execute: block)\n        }\n    }\n\n    private static func unwrap(_ value: Any?) -&gt; String {\n        guard let value else { return \"null\" }\n        if let str = value as? String { return peelJsonStringIfNeeded(str) }\n        if let str = value as? NSString { return peelJsonStringIfNeeded(str as String) }\n        if JSONSerialization.isValidJSONObject(value),\n           let data = try? JSONSerialization.data(withJSONObject: value),\n           let json = String(data: data, encoding: .utf8) { return json }\n        if let num = value as? NSNumber { return num.stringValue }\n        return \"null\"\n    }\n\n    private static func peelJsonStringIfNeeded(_ value: String) -&gt; String {\n        guard let data = value.data(using: .utf8),\n              let parsed = try? JSONSerialization.jsonObject(with: data)\n        else { return value }\n        if let inner = parsed as? String { return inner }\n        return value\n    }\n\n    private func jsonQuote(_ string: String) -&gt; String {\n        guard let data = try? JSONEncoder().encode(string),\n              let encoded = String(data: data, encoding: .utf8)\n        else { return \"\\\"\\\"\" }\n        return encoded\n    }\n\n    private func resolve(id: String, valueJson: String?) {\n        let valuePart = valueJson.map { jsonQuote($0) } ?? \"null\"\n        eval(\"window.__plResolveCallback(\\(jsonQuote(id)), \\(valuePart))\")\n    }\n\n    private func reject(id: String, error: String) {\n        eval(\"window.__plRejectCallback(\\(jsonQuote(id)), \\(jsonQuote(error)))\")\n    }\n\n    private func onMain(_ block: @escaping () -&gt; Void) { dispatchMain(block) }\n\n    private final class JsResponder: Responder {\n        private var settled = false\n        private let id: String\n        private weak var bridge: PleasedBridge?\n        init(id: String, bridge: PleasedBridge) {\n            self.id = id\n            self.bridge = bridge\n        }\n        func resolve(valueJson: String?) {\n            guard !settled else { return }\n            settled = true\n            bridge?.resolve(id: id, valueJson: valueJson)\n        }\n        func reject(error: String) {\n            guard !settled else { return }\n            settled = true\n            bridge?.reject(id: id, error: error)\n        }\n    }\n\n    private final class NoopResponder: Responder {\n        static let shared = NoopResponder()\n        func resolve(valueJson: String?) {}\n        func reject(error: String) {}\n    }\n}\n\nextension PleasedBridge: WKScriptMessageHandler {\n    func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {\n        guard message.name == \"pleasedNative\",\n              let body = message.body as? String,\n              let data = body.data(using: .utf8),\n              let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],\n              let kind = json[\"kind\"] as? String\n        else { return }\n\n        switch kind {\n        case \"loader_ready\":\n            onMain { self.onLoaderReady?() }\n        case \"log\":\n            if let text = json[\"message\"] as? String { onMain { self.onLog?(text) } }\n        case \"event\":\n            let name = json[\"name\"] as? String ?? \"\"\n            let via = json[\"via\"] as? String ?? \"\"\n            let wildcard = json[\"wildcard\"] as? Bool ?? false\n            let payloadString = Self.jsonPayloadString(from: json[\"payload\"])\n            if wildcard {\n                var envelope: [String: Any] = [\"event\": name]\n                envelope[\"payload\"] = json[\"payload\"] ?? NSNull()\n                let envelopeJson = (try? JSONSerialization.data(withJSONObject: envelope))\n                    .flatMap { String(data: $0, encoding: .utf8) }\n                onMain {\n                    if let handler = self.handler(for: \"\\(via)|*\") {\n                        handler(envelopeJson, NoopResponder.shared)\n                    }\n                }\n            } else if via.isEmpty {\n                onMain {\n                    if let handler = self.handler(for: \"event:on|\\(name)\") {\n                        handler(payloadString, NoopResponder.shared)\n                    }\n                    if let handler = self.handler(for: \"event:once|\\(name)\") {\n                        handler(payloadString, NoopResponder.shared)\n                    }\n                }\n            } else {\n                onMain {\n                    if let handler = self.handler(for: \"\\(via)|\\(name)\") {\n                        handler(payloadString, NoopResponder.shared)\n                    }\n                }\n            }\n        case \"callback\":\n            let name = json[\"name\"] as? String ?? \"\"\n            let id = json[\"id\"] as? String ?? \"\"\n            let type = json[\"type\"] as? String ?? \"\"\n            let payloadString = Self.jsonPayloadString(from: json[\"payload\"])\n            guard let handler = handler(for: \"\\(type)|\\(name)\") else {\n                reject(id: id, error: \"no handler registered for \\(name)\")\n                return\n            }\n            onMain { handler(payloadString, JsResponder(id: id, bridge: self)) }\n        default:\n            break\n        }\n    }\n\n    private func handler(for key: String) -&gt; CallbackHandler? {\n        lock.lock()\n        defer { lock.unlock() }\n        return handlers[key]\n    }\n\n    static func jsonPayloadString(from raw: Any?) -&gt; String? {\n        guard let raw, !(raw is NSNull) else { return nil }\n        if let str = raw as? String { return str }\n        if JSONSerialization.isValidJSONObject(raw),\n           let data = try? JSONSerialization.data(withJSONObject: raw),\n           let str = String(data: data, encoding: .utf8) { return str }\n        return nil\n    }\n}\n\u003C\u002Fpre>\u003Chr>\u003Ch2>Step 3: Add the chat screen\u003C\u002Fh2>\u003Cp>Replace \u003Ccode>YOUR_CLIENT_ID\u003C\u002Fcode> and \u003Ccode>YOUR_WIDGET_ID\u003C\u002Fcode> with your real values.\u003C\u002Fp>\u003Cpre class=\"ql-syntax\" spellcheck=\"false\">import UIKit\nimport WebKit\n\nfinal class ChatViewController: UIViewController {\n    private var webView: WKWebView!\n    private var pleased: PleasedWebViewSetup!\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        let config = WKWebViewConfiguration()\n        config.defaultWebpagePreferences.allowsContentJavaScript = true\n        PleasedWebViewSetup.applyMediaPlaybackPolicy(to: config)\n\n        webView = WKWebView(frame: view.bounds, configuration: config)\n        webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]\n        view.addSubview(webView)\n\n        pleased = PleasedWebViewSetup(webView: webView)\n        pleased.configure()\n\n        let url = URL(string:\n            \"https:\u002F\u002Fcdn.pleased.com\u002Fwidget\u002Fnative\u002Findex.html\" +\n            \"?clientId=YOUR_CLIENT_ID&amp;widgetId=YOUR_WIDGET_ID&amp;platform=ios\"\n        )!\n        webView.load(URLRequest(url: url))\n    }\n}\n\u003C\u002Fpre>\u003Cp>Open it from your app:\u003C\u002Fp>\u003Cpre class=\"ql-syntax\" spellcheck=\"false\">let chat = ChatViewController()\nchat.modalPresentationStyle = .fullScreen\npresent(chat, animated: true)\n\u003C\u002Fpre>\u003Cp>Remember:\u003C\u002Fp>\u003Cul>\u003Cli>Set your app’s minimum deployment target to iOS 15+ in Xcode.\u003C\u002Fli>\u003Cli>Call \u003Ccode>applyMediaPlaybackPolicy(to:)\u003C\u002Fcode> before creating the \u003Ccode>WKWebView\u003C\u002Fcode>.\u003C\u002Fli>\u003Cli>Use \u003Ccode>platform=ios\u003C\u002Fcode> in the URL (use \u003Ccode>platform=app\u003C\u002Fcode> on Android).\u003C\u002Fli>\u003Cli>\u003Ccode>NSCameraUsageDescription\u003C\u002Fcode> is required on a real device if visitors use Take Photo when attaching.\u003C\u002Fli>\u003C\u002Ful>\u003Chr>\u003Ch2>Step 4: Sign in your users and drive the chat\u003C\u002Fh2>\u003Cp>Use this complete chat screen (it replaces Step 3 when you need tokens and events):\u003C\u002Fp>\u003Cpre class=\"ql-syntax\" spellcheck=\"false\">import UIKit\nimport WebKit\n\nfinal class ChatViewController: UIViewController {\n    private var webView: WKWebView!\n    private var pleased: PleasedWebViewSetup!\n    private var bridge: PleasedBridge!\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        let config = WKWebViewConfiguration()\n        config.defaultWebpagePreferences.allowsContentJavaScript = true\n        PleasedWebViewSetup.applyMediaPlaybackPolicy(to: config)\n\n        bridge = PleasedBridge(configuration: config)\n\n        webView = WKWebView(frame: view.bounds, configuration: config)\n        webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]\n        view.addSubview(webView)\n\n        bridge.bind(webView: webView)\n\n        bridge.onLoaderReady = { [weak self, weak bridge] in\n            guard let bridge else { return }\n\n            bridge.registerCallback(type: \"set:callback\", name: \"token\") { _, respond in\n                fetchTokenFromYourBackend { token in\n                    let quoted = (try? JSONEncoder().encode(token))\n                        .flatMap { String(data: $0, encoding: .utf8) } ?? #\"\"\"\"#\n                    respond.resolve(valueJson: quoted)\n                }\n            }\n\n            bridge.registerCallback(type: \"event:on\", name: \"ready\") { [weak bridge] _, _ in\n                bridge?.invoke(\"widget:open\", payloadJson: \"{}\")\n            }\n\n            bridge.registerCallback(type: \"event:on\", name: \"close\") { [weak self] _, _ in\n                self?.dismiss(animated: true)\n            }\n\n            bridge.registerCallback(type: \"event:on\", name: \"request_open_settings\") { _, _ in\n                if let url = URL(string: UIApplication.openSettingsURLString) {\n                    UIApplication.shared.open(url)\n                }\n            }\n            bridge.invoke(\n                \"set:config\",\n                payloadJson: #\"{\"capabilities\":{\"canOpenAppSettings\":true}}\"#\n            )\n        }\n\n        pleased = PleasedWebViewSetup(webView: webView)\n        pleased.configure()\n\n        let url = URL(string:\n            \"https:\u002F\u002Fcdn.pleased.com\u002Fwidget\u002Fnative\u002Findex.html\" +\n            \"?clientId=YOUR_CLIENT_ID&amp;widgetId=YOUR_WIDGET_ID&amp;platform=ios\"\n        )!\n        webView.load(URLRequest(url: url))\n    }\n}\n\u003C\u002Fpre>\u003Cblockquote>Important — retain cycles: \u003Ccode>PleasedBridge\u003C\u002Fcode> keeps every handler you register. Use \u003Ccode>[weak self]\u003C\u002Fcode> and \u003Ccode>[weak bridge]\u003C\u002Fcode> on each closure. In \u003Ccode>onLoaderReady\u003C\u002Fcode>, use \u003Ccode>guard let bridge else { return }\u003C\u002Fcode> only — not \u003Ccode>guard let self\u003C\u002Fcode>, or nested handlers can keep the chat screen and \u003Ccode>WKWebView\u003C\u002Fcode> alive after dismiss.\u003C\u002Fblockquote>\u003Cp>Keep the \u003Ccode>close\u003C\u002Fcode> handler so minimising the chat does not leave an empty screen.\u003C\u002Fp>\u003Chr>\u003Ch3>Get the key (signed-in visitors)\u003C\u002Fh3>\u003Col>\u003Cli>Settings → Chat Widget Setup in Pleased.\u003C\u002Fli>\u003Cli>Widget Authentication → Reveal.\u003C\u002Fli>\u003C\u002Fol>\u003Cblockquote>Important: Keep the key on your server only. Never embed it in the app.\u003C\u002Fblockquote>\u003Ch3>Create the token on your server\u003C\u002Fh3>\u003Cp>Same as Android: JWE with your public key (\u003Ccode>RSA-OAEP-256\u003C\u002Fcode>, \u003Ccode>A128GCM\u003C\u002Fcode>). See the&nbsp;\u003Ca href=\"https:\u002F\u002Fcdn.pleased.com\u002Fwidget-help\u002Fwidget-token.html\" rel=\"noopener noreferrer\" target=\"_blank\">Widget Token\u003C\u002Fa> guide for a Java example.\u003C\u002Fp>\u003Ch3>Pass the token to the widget\u003C\u002Fh3>\u003Cpre class=\"ql-syntax\" spellcheck=\"false\">func fetchTokenFromYourBackend(onToken: @escaping (String) -&gt; Void) {\n    guard isSignedIn() else {\n        onToken(\"\")\n        return\n    }\n    DispatchQueue.global().async {\n        let token = (try? String(contentsOf: URL(string: \"https:\u002F\u002Fapi.example.com\u002Fpleased-token\")!)) ?? \"\"\n        DispatchQueue.main.async { onToken(token) }\n    }\n}\n\u003C\u002Fpre>\u003Cp>If the visitor signs in or out while the chat is open, call \u003Ccode>bridge.invoke(\"widget:re_auth\")\u003C\u002Fcode>.\u003C\u002Fp>\u003Chr>\u003Ch2>File attachments\u003C\u002Fh2>\u003Cp>On iOS you do not add file-picker code. \u003Ccode>WKWebView\u003C\u002Fcode> shows the system picker.\u003C\u002Fp>\u003Cp>Because the input accepts images, the picker offers Take Photo on a real iPhone. You need \u003Ccode>NSCameraUsageDescription\u003C\u002Fcode> from Step 1.\u003C\u002Fp>\u003Cblockquote>Important: If you replace \u003Ccode>PleasedWebViewSetup\u003C\u002Fcode> as \u003Ccode>navigationDelegate\u003C\u002Fcode> or \u003Ccode>uiDelegate\u003C\u002Fcode>, you must keep the same link and navigation behaviour, or attachments and chat links may stop working.\u003C\u002Fblockquote>\u003Chr>\u003Ch2>Voice calls\u003C\u002Fh2>\u003Cp>\u003Ccode>PleasedWebViewSetup\u003C\u002Fcode> answers WebKit’s microphone request (iOS 15+). The visitor sees the system permission dialog.\u003C\u002Fp>\u003Cp>On iOS, WebKit passes the delegate the top-level page origin (the host page you loaded), not the widget iframe origin as on Android. You normally do not need extra “widget origin” configuration when you load Pleased’s host page from the CDN.\u003C\u002Fp>\u003Cp>When the microphone is blocked, register \u003Ccode>request_open_settings\u003C\u002Fcode> and set \u003Ccode>canOpenAppSettings\u003C\u002Fcode> as in Step 4.\u003C\u002Fp>\u003Cul>\u003Cli>With that handler: the visitor may see blocked-microphone copy and an Open settings button (when the widget treats your integration as able to open settings).\u003C\u002Fli>\u003Cli>Without it: the visitor sees “Microphone access is blocked for this site…” with Try again — not an in-app Open settings shortcut. They must open Settings → Your app themselves.\u003C\u002Fli>\u003C\u002Ful>\u003Cp>Test voice on a physical iPhone when you can; the Simulator is not enough for real capture.\u003C\u002Fp>\u003Chr>\u003Ch2>Verify the installation\u003C\u002Fh2>\u003Col>\u003Cli>Build and run on a real device (at least once for camera + mic).\u003C\u002Fli>\u003Cli>Chat opens; signed-in greeting shows the user’s name.\u003C\u002Fli>\u003Cli>Attach a file; try Take Photo (needs camera key).\u003C\u002Fli>\u003Cli>With an agent online, start a call and allow the microphone.\u003C\u002Fli>\u003Cli>Minimise the chat; you should return to the previous screen (\u003Ccode>close\u003C\u002Fcode> handler).\u003C\u002Fli>\u003C\u002Fol>\u003Cp>Debug: Safari → Develop → [device] → [your app].\u003C\u002Fp>\u003Chr>\u003Ch2>Troubleshooting\u003C\u002Fh2>\u003Cul>\u003Cli>Chat never appears: check client ID and widget ID; HTTPS if self-hosted.\u003C\u002Fli>\u003Cli>Guests when signed in: \u003Ccode>token\u003C\u002Fcode> callback \u002F server token \u002F phone format.\u003C\u002Fli>\u003Cli>Bubble over your UI: add \u003Ccode>platform=ios\u003C\u002Fcode>.\u003C\u002Fli>\u003Cli>Blank after minimise: handle \u003Ccode>close\u003C\u002Fcode>.\u003C\u002Fli>\u003Cli>No mic prompt: add \u003Ccode>NSMicrophoneUsageDescription\u003C\u002Fcode>; deployment target iOS 15+; call \u003Ccode>configure()\u003C\u002Fcode>.\u003C\u002Fli>\u003Cli>Crash on Take Photo: add \u003Ccode>NSCameraUsageDescription\u003C\u002Fcode>.\u003C\u002Fli>\u003Cli>\u003Ccode>NotAllowedError\u003C\u002Fcode>, no prompt: earlier deny, custom mic delegate, or iframe without \u003Ccode>allow=\"microphone\"\u003C\u002Fcode>.\u003C\u002Fli>\u003Cli>Links\u002Fdownloads in chat do nothing: do not replace navigation delegate without \u003Ccode>target=\"_blank\"\u003C\u002Fcode> handling.\u003C\u002Fli>\u003Cli>Blocked mic, no Open settings: add \u003Ccode>request_open_settings\u003C\u002Fcode> + \u003Ccode>canOpenAppSettings\u003C\u002Fcode>.\u003C\u002Fli>\u003Cli>No call playback: call \u003Ccode>applyMediaPlaybackPolicy\u003C\u002Fcode> before creating \u003Ccode>WKWebView\u003C\u002Fcode>.\u003C\u002Fli>\u003Cli>Chat screen won’t go away \u002F memory: weak captures in bridge handlers (see Step 4).\u003C\u002Fli>\u003Cli>Only Open Request: no agent online.\u003C\u002Fli>\u003C\u002Ful>\u003Cp>\u003Cbr>\u003C\u002Fp>","2026-11-12T09:54:16.000+00:00",13,"2026-11-12T11:42:48.000+00:00","Divyank Mishra","integrating-the-chatbot-into-your-ios-application",[57],{"id":48,"brandId":18,"categoryId":58,"parentSectionId":32,"position":48,"title":59,"description":60,"titleTranslated":32,"descriptionTranslated":32,"sections":32,"articles":32,"isActive":19,"language":27,"englishVersion":19,"isInternal":43},3,"General Guides","Quick Start Guides",{"id":58,"brandId":18,"position":58,"title":62,"description":63,"titleTranslated":32,"descriptionTranslated":32,"isActive":19,"language":27,"englishVersion":19,"isInternal":43},"Getting Started","Getting Started with Pleased",[65,69,74,78,82,86,90,94,98],{"id":66,"brandId":18,"sectionId":48,"categoryId":32,"categoryName":32,"categoryNameTranslated":32,"title":67,"titleTranslated":32,"position":66,"isDraft":43,"isPromoted":19,"isActive":19,"language":27,"englishVersion":19,"updatedAt":32,"isInternal":32,"includeForAi":32,"expiryTime":32,"slug":68,"priority":43,"isPriority":43},82,"Inviting teammates","inviting-teammates",{"id":70,"brandId":18,"sectionId":48,"categoryId":32,"categoryName":32,"categoryNameTranslated":32,"title":71,"titleTranslated":32,"position":72,"isDraft":43,"isPromoted":19,"isActive":19,"language":27,"englishVersion":19,"updatedAt":32,"isInternal":32,"includeForAi":32,"expiryTime":32,"slug":73,"priority":43,"isPriority":43},104,"Configuring your Chatbot",93,"configuring-your-chatbot",{"id":75,"brandId":18,"sectionId":48,"categoryId":32,"categoryName":32,"categoryNameTranslated":32,"title":76,"titleTranslated":32,"position":75,"isDraft":43,"isPromoted":43,"isActive":19,"language":27,"englishVersion":19,"updatedAt":32,"isInternal":32,"includeForAi":32,"expiryTime":32,"slug":77,"priority":43,"isPriority":43},78,"Going online for customers","going-online-for-customers",{"id":79,"brandId":18,"sectionId":48,"categoryId":32,"categoryName":32,"categoryNameTranslated":32,"title":80,"titleTranslated":32,"position":79,"isDraft":43,"isPromoted":43,"isActive":19,"language":27,"englishVersion":19,"updatedAt":32,"isInternal":32,"includeForAi":32,"expiryTime":32,"slug":81,"priority":43,"isPriority":43},79,"Navigating Pleased","navigating-pleased",{"id":83,"brandId":18,"sectionId":48,"categoryId":32,"categoryName":32,"categoryNameTranslated":32,"title":84,"titleTranslated":32,"position":83,"isDraft":43,"isPromoted":43,"isActive":19,"language":27,"englishVersion":19,"updatedAt":32,"isInternal":32,"includeForAi":32,"expiryTime":32,"slug":85,"priority":43,"isPriority":43},80,"Understanding the dashboard","understanding-the-dashboard",{"id":87,"brandId":18,"sectionId":48,"categoryId":32,"categoryName":32,"categoryNameTranslated":32,"title":88,"titleTranslated":32,"position":87,"isDraft":43,"isPromoted":43,"isActive":19,"language":27,"englishVersion":19,"updatedAt":32,"isInternal":32,"includeForAi":32,"expiryTime":32,"slug":89,"priority":43,"isPriority":43},81,"Using notifications","using-notifications",{"id":72,"brandId":18,"sectionId":48,"categoryId":32,"categoryName":32,"categoryNameTranslated":32,"title":91,"titleTranslated":32,"position":92,"isDraft":43,"isPromoted":43,"isActive":19,"language":27,"englishVersion":19,"updatedAt":32,"isInternal":32,"includeForAi":32,"expiryTime":32,"slug":93,"priority":43,"isPriority":43},"Customising your Chatbot",94,"customising-your-chatbot",{"id":95,"brandId":18,"sectionId":48,"categoryId":32,"categoryName":32,"categoryNameTranslated":32,"title":96,"titleTranslated":32,"position":95,"isDraft":43,"isPromoted":43,"isActive":19,"language":27,"englishVersion":19,"updatedAt":32,"isInternal":32,"includeForAi":32,"expiryTime":32,"slug":97,"priority":43,"isPriority":43},112,"Integrating the Chatbot into your Android application","integrating-the-chatbot-into-your-android-application",{"id":47,"brandId":18,"sectionId":48,"categoryId":32,"categoryName":32,"categoryNameTranslated":32,"title":49,"titleTranslated":32,"position":47,"isDraft":43,"isPromoted":43,"isActive":19,"language":27,"englishVersion":19,"updatedAt":32,"isInternal":32,"includeForAi":32,"expiryTime":32,"slug":55,"priority":43,"isPriority":43},[]]