Add in-app support to a Mac app (Swift)
Give your macOS app a "Get help" button that shares your app's window with your support team, with consent, in your own name, colour and logo.
Give your Mac app a "Get help" button: your customer clicks it and agrees, and your support team sees your app's window in the GaiaDesk console — and, if you allow it, guides it — without the customer installing anything.
GaiaDesk's Swift SDK is the Swift package GaiaDeskEmbed, for macOS 12.3 or later (Apple silicon and Intel). Its Swift is open source (MIT), at github.com/Gaia-Desk/gaiadesk-embed-swift. It wraps the same signed native library, libgaiadesk_embed, as GaiaDesk's other embed SDKs; the library is a prebuilt binary that ships, unmodified, inside your app. For how in-app support fits together, see In-app support.
What your customer sees
One button. Your app shows "Get help" wherever you put it.
A consent dialog in your colours. It names your company, says what will be shared (this app's window, or the screen if you chose it) and whether your team will be able to guide it. Nothing is shared until the customer agrees. It opens as a sheet on the window that asked, never behind it. For a live preview, choices, who is waiting and a stored receipt, use the consent step.
An indicator for as long as anything is shared. "Sharing with Acme · Stop sharing", drawn by the library on top of your app. Your app cannot hide it. In a guided session it also has Pause control. While the customer waits for an agent it offers Cancel instead, and your customer can drag it anywhere (see The indicator).
A support code. Nine digits your customer can read to an agent over the phone.
When the session ends — the customer presses Stop sharing, your app stops it, the session expires, or the app quits — sharing stops at once and nothing is left behind: the library installs nothing, runs no service and writes nothing to disk.
What your support team sees
Agents open Support in the GaiaDesk console, see the waiting customer (with the details your backend passed) and join, or type the support code. Only your own account and team can join, and only team members with a support seat.
1. Add the package
In Package.swift:
dependencies: [
.package(url: "https://github.com/Gaia-Desk/gaiadesk-embed-swift.git", from: "0.4.0"),
],
targets: [
.target(name: "MyApp", dependencies: [
.product(name: "GaiaDeskEmbed", package: "gaiadesk-embed-swift"),
]),
]In Xcode: File › Add Package Dependencies…, enter the same URL, and add the GaiaDeskEmbed library to your app target.
2. The native library
SwiftPM downloads the library for you: GaiaDeskEmbedFFI.xcframework, a universal XCFramework (Apple silicon and Intel), from the package's GitHub release. It refuses the download unless it matches the checksum pinned in the package's Package.swift, and links it into your app.
To build against a local copy instead, scripts/fetch-binary.sh 0.4.0 (in a checkout of the package) downloads the release's XCFramework into Frameworks/, checking the same checksum; then build with GAIADESK_EMBED_LOCAL_BINARY=1.
3. Create sessions on your backend
Your server decides who may get help. It creates the support session with a secret API key (scope support) and hands the app only its embed token:
curl -s -X POST https://api.gaiadesk.net/v1/support/sessions \
-H "Authorization: Bearer $GAIADESK_API_KEY" -H "Content-Type: application/json" \
-d '{"mode": "view", "customer": {"name": "Ada", "plan": "pro"}}'The response carries embed_token (gdemb_…), which your app passes to GaiaDeskEmbed.start as embedToken. mode is view (look only) or cobrowse (see Guided sessions).
Never ship the secret key in your app: the embed token is all it needs. The full request is in the support API reference.
4. Add the button
import AppKit
import GaiaDeskEmbed
@MainActor
final class HelpController {
private var help: GaiaDeskEmbed? // keep it: releasing it stops sharing
func getHelp(token: String, window: NSWindow, cardField: NSView, status: NSTextField) {
guard help == nil else { return }
// 1. Ask, with the library's dialog.
guard GaiaDeskEmbed.requestConsent(company: "Acme") == true else { return }
// 2. Start with the answer, and the masks you already know.
let masks = GaiaDeskEmbed.rectInWindow(cardField).map { [$0] } ?? []
do {
help = try GaiaDeskEmbed.start(
.init(embedToken: token, company: "Acme", windowNumber: window.windowNumber, maskedRects: masks),
consentGranted: true
) { [weak self] event in
switch event {
case let .code(code, _, _): status.stringValue = "Your support code is \(code)"
case .ended: self?.help = nil
default: break
}
}
} catch let e as GaiaDeskEmbedError {
status.stringValue = "Could not start: \(e.message) (\(e.code))"
} catch {
status.stringValue = "Could not start: \(error)"
}
}
func stopHelp() {
help?.stop()
}
}start refuses with GaiaDeskEmbedError code consent_required unless consentGranted is true — and it must be your customer's answer to a consent dialog, the library's or your own. requestConsent(company:) must run on the main thread (it returns nil elsewhere). Events arrive on the main queue:
Event | |
|---|---|
|
|
| right after |
| the session is up; the first value is the support code |
| an agent joined (their email, when known) / left |
| guided input paused or allowed again |
| an agent's request and what became of it |
| e.g. |
| the customer dragged the indicator (keep it for |
|
|
Event gained cases in 0.4.0, so an exhaustive switch over it needs them.
The consent step (recommended)
Use the library's consent step, consent(_:) (package and libgaiadesk_embed 0.4.0), rather than consentGranted: true after a dialog of your own. It gives you, with no UI to build:
a live preview of exactly what support will see, masked fields already black;
per-session choices for the customer: allow click-and-type or keep it view-only, share app logs, one window or the whole screen (each only when you offer it);
who is waiting and for how long, links to your privacy policy and terms, and an optional auto-decline timeout;
a consent receipt (who agreed to what, when, to which wording, hashed), stored on the session and shown in the console (see Proof of consent);
wording localized into 14 languages (or your own), and an accessible dialog: keyboard only, Enter accepts, Esc declines, VoiceOver labels, reduced motion.
let decision = try GaiaDeskEmbed.consent(.init(
company: "Acme", guided: true, masked: true, parentWindow: window,
theme: .init(accent: "#0f766e", radius: 12),
choices: .init(offerGuided: true, offerLogs: true),
privacyURL: URL(string: "https://acme.example/privacy"),
server: URL(string: "https://gaiadesk.net"), embedToken: token, sessionId: sessionId,
// all three: the library posts the receipt, shows who is waiting
windowNumber: window.windowNumber, maskedRects: masks
)) { event in print(event) } // .consentShown, .consentAccepted / .consentDeclined
switch decision.decision {
case .accepted: help = try GaiaDeskEmbed.start(config, consent: decision) { event in /* … */ }
case .declined, .timeout: break // the receipt says so; the session leaves the queue
case .unavailable: break // no dialog here: ask with your own, then recordConsent
}start(_:consent:onEvent:) sends the decision's consentToken and consentReceipt with the join (also Configuration.consentToken / consentReceipt) and starts with what the customer chose (their capture; guided only if they allowed it). Main thread only (wrong_thread otherwise); refused options throw bad_config, never a decline. A decline or timeout ends the waiting request (customer_declined / consent_timeout).
| the dialog → a |
| the same picture ( |
| your own UI's answer (decision, choices, the strings you showed) → the same |
| start with the decision |
requestConsent still works as in 0.3.0.
Your name, colour and logo
company puts your name on the consent dialog and on the "Sharing with Acme · Stop sharing" indicator. Add your colour and logo to the Configuration, and pass ConsentOptions to requestConsent(_:) for the dialog in your look:
let logo = try Data(contentsOf: Bundle.main.url(forResource: "logo", withExtension: "png")!)
guard try GaiaDeskEmbed.requestConsent(.init(company: "Acme", brandColor: "#0f766e", logoPNG: logo)) == true else { return }
help = try GaiaDeskEmbed.start(
.init(embedToken: token, company: "Acme", windowNumber: window.windowNumber, brandColor: "#0f766e", logoPNG: logo),
consentGranted: true
) { event in /* … */ }Field | |
|---|---|
| "Sharing with Acme". Required. |
| Accent colour, |
| A PNG, at most 256 KiB, as |
A colour that is not #RRGGBB throws GaiaDeskEmbedError (bad_config) before anything native runs; a logo the library refuses throws bad_config from requestConsent(_:) or start, and is never read as a decline. Colour and logo need version 0.2.0 or later of the library; package 0.4.0 downloads library 0.4.0.
ConsentOptions also takes masked: true (the dialog says private fields stay hidden; pass the masks too) and parentWindow: the dialog is a sheet on that window, never behind it (default: your app's focused window). Without a logo it shows your app icon.
The indicator
The indicator starts top right, clear of the window that asked (parentWindow in the Configuration; default your app's focused window), or in the corner indicatorPosition names (.topLeft, .topRight, .bottomLeft, .bottomRight). Your customer can drag it; each drag sends .indicatorMoved(x:y:). The library writes nothing to disk, so keep the place yourself and pass it back as indicatorOrigin next time (restored while it fits on a screen):
case let .indicatorMoved(x, y): UserDefaults.standard.set([x, y], forKey: "helpIndicator")
// next start:
if let p = UserDefaults.standard.array(forKey: "helpIndicator") as? [Double], p.count == 2 {
config.indicatorOrigin = CGPoint(x: p[0], y: p[1])
}Until an agent is admitted the indicator offers Cancel: the request leaves your support team's queue at once and the session ends with customer_cancelled (as does stop() before an agent was admitted). That is also the session's end_reason in the API and in webhooks.
Guided sessions
By default your team can only look. To let them click and type, create the session as cobrowse (mode: "cobrowse") and pass guided: true in the Configuration — both ends must want it. Pass guided: true to requestConsent too, so the dialog says so. Their input is delivered inside your app's own process, only to your app's windows, only while your app is in front, never on a masked view, and at most 20 actions a second. Your customer can pause it at any time from the indicator; your app can too (setPaused(true)). Every request arrives as an .action event, with a reason when it was not applied.
Keeping things private
Your app's window only. By default (
capture: .window) the library shares one window:windowNumber, or your app's frontmost..appshares every window of your app; other apps, notifications and the desktop are never captured, unless you choose.screen.Masks. Mark anything sensitive — card numbers, balances, passwords — as a masked view. It is painted black before a frame is encoded. Pass the ones you already know in
maskedRectswhen you start (rectInWindow(_:)turns a view into one): only start-time masks are guaranteed to cover the very first frame. Afterwards,setMaskedViews(_:)takes views andsetMaskedRects(_:)takes rects (relative to the top-left of the shared window's frame, in points); each call replaces the last. Call again when your layout changes. If the window cannot be located, the whole picture is blacked out.Consent every time. The library refuses to start without it; there is no setting that skips the dialog or hides the indicator.
What each platform supports
Capture | Guided input | Consent dialog | |
|---|---|---|---|
macOS 12.3 or later (universal: Apple silicon and Intel) | window, app, screen | yes | native, branded |
Screen Recording: your app needs this permission; macOS asks your customer the first time a session starts.
NSScreenCaptureUsageDescriptionis not required.For Windows and Linux, use the C and C++ SDK or the Electron SDK.
What is and is not permitted
You may: ship the prebuilt library unmodified inside your app, with its licence in your app's notices; offer support sessions to your own customers; brand the dialog and indicator with your name, colour and logo.
You may not: modify, decompile or re-sign the library separately from your app; hide or imitate the indicator; start a session without your customer's agreement.
The package's Swift is MIT; the native library is under the GaiaDesk Native Binary Licence (LICENSE-BINARY). See the package's README for every option, event and error code.