iOS SDK
Install agent44 in a SwiftUI or UIKit app: configure it, identify signed-in users with a signature, open the chat and help center, show update prompts and set up push.
AAgent44Updated 8 min read
On this page
Add customer support to your iOS app in a few minutes: a chat with your team and AI agent, a help center, "update your app" screens and What's New. You manage all of it from your agent44 dashboard.
SwiftUI and UIKit, iOS 15 and newer. Written in Swift, no dependencies.
Also for Flutter, Android and React Native, with the same screens and the same behaviour.
The full reference, with every option, is the SDK's README on GitHub: harithwick/agent44-ios.
Quick start#
1. Get your SDK key#
In agent44, open Settings › Apps, pick your iOS app (or Add app) and click Create SDK key. Copy it: it starts with a44_pub_ and is shown only once.
2. Install the package#
Swift Package Manager (Xcode: File › Add Package Dependencies…):
https://github.com/harithwick/agent44-iosAdd the Agent44 product to your app target. (Agent44Core is every API without the screens, for apps that build their own.)
Or in a Package.swift:
.package(url: "https://github.com/harithwick/agent44-ios", from: "0.1.0"),
// …
.product(name: "Agent44", package: "agent44-ios"),CocoaPods:
pod 'Agent44', '~> 0.1'So users can attach photos, the SDK uses the system photo picker, which needs no permission. If your app reads the photo library elsewhere, keep your own NSPhotoLibraryUsageDescription in Info.plist; the SDK doesn't need one.
3. Start the SDK#
SwiftUI:
import Agent44
import SwiftUI
@main
struct MyApp: App {
init() {
Agent44.configure(publicKey: "a44_pub_YOUR_IOS_KEY")
}
var body: some Scene {
WindowGroup { ContentView() }
}
}UIKit: call Agent44.configure(publicKey:) in application(_:didFinishLaunchingWithOptions:).
configure returns at once and never waits on the network. Calls made while it's starting (identify, a screen) wait for it.
4. Add a chat button#
Put the round chat button in the corner of any screen. It shows the unread count, and a tap opens the chat:
ContentView()
.agent44Launcher() // bottom left or right, as set in agent44UIKit: add an Agent44LauncherButton to your view and pin it to a corner.
Or open the chat from your own button:
Button("Chat with us") { Agent44.openChat() }That's it. Run your app, tap the button and send a message. It appears in your agent44 inbox, and the "Install the SDK" step in your dashboard's setup checklist ticks itself off.
Before you submit to the App Store, see "Data the SDK collects" in the SDK's README for the privacy labels. The SDK ships a privacy manifest (PrivacyInfo.xcprivacy) that Xcode adds to your app's privacy report.
Tell agent44 who your users are#
Call this after your user signs in, so your team knows who they're talking to and the user sees their conversations on every device:
try await Agent44.identify(Agent44User(
userId: user.id, // your app's own user id
email: user.email, // everything else is optional
name: user.name,
phone: user.phone,
avatarUrl: user.photoURL?.absoluteString, // a String
company: Agent44Company(
name: "Acme",
url: "https://acme.com",
employment: Agent44Employment(title: "CTO"),
geolocation: Agent44Geolocation(city: "London", country: "GB")
),
signature: user.agent44Hash // see "Verify your users" below
))Or the short form: try await Agent44.identify(userId: user.id, email: user.email, signature: user.agent44Hash).
And when they sign out:
await Agent44.logout()identify throws an Agent44Error when agent44 can't be reached. Catch it and try again later: the previous identity stays in place until it works. logout never throws, so it's safe to call in your sign-out flow. "Error handling" in the README lists what every call throws.
People can chat before they sign in too. Their conversations move to their account when you call identify.
Verify your users#
Without verification, agent44 trusts the id you send. Anyone with your app's key and a user's id could then read that user's conversations. Identity verification stops that, and new workspaces start with it enforced: until your server signs user ids, identify is refused (401) and signed-in screens show their error state, while people who haven't signed in chat as usual.
In agent44, open Settings › Identity verification and click Generate secret. The secret starts with
a44_idv_and is shown only once: copy it into your server's configuration. It belongs on your server only. One secret covers every app in the workspace (iOS, Android and web).When your app signs in, have your server compute the HMAC-SHA256 of the user's id, keyed with the whole secret (the
a44_idv_included). Return it as lowercase hex.Pass it as
signaturetoAgent44.identify. The SDK sends it with every request (X-A44-User-Hash).If Enforce is off in your workspace, click Turn on Enforce once your app version with signatures is live.
// Node, on your server
crypto.createHmac('sha256', process.env.AGENT44_IDENTITY_SECRET).update(user.id).digest('hex');While Enforce is off, a missing or wrong signature is ignored and the id is trusted as sent, so you can ship the app version that sends signatures first. While it's on, a user id with a missing or wrong signature gets a 401: identify throws an Agent44Error with statusCode 401 (isUnauthorized), nothing is saved, and the screens show their error state. If your app has no server that could sign ids, an admin can turn Enforce off in the same place; use ids that can't be guessed then.
Rotate secret replaces the secret at once, and signatures made with the old one stop matching. With Enforce on, update your server straight after rotating.
Either way, use ids that can't be guessed: your database id or a UUID, not an email address or a number like 42.
Where the signature is kept#
The SDK keeps the user id and signature in the Keychain (kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly: readable after the first unlock, so a launch from a push works, and never copied to another device by a backup). Everything else (the anonymous id, the last app version, which messages were seen) is in UserDefaults, under keys starting with agent44..
A reinstall starts signed out. Keychain items outlive the app, so the SDK ignores what it finds there until this install has written it.
logout()clears both. If the Keychain can't delete, the SDK ignores what's left from then on.Pass your own
storage:toconfigure(anything conforming toAgent44Storage) to keep the values elsewhere;SecureIdentityStorage(secure:storage:)splits them the same way.
Everything you can open#
Each of these is one line, called from any button or menu. They present over your app's top view controller; pass from: to choose one.
What | Code |
|---|---|
The chat (latest open conversation, or a new one) |
|
Messenger (home, messages, help and updates tabs) |
|
Start a new message |
|
One conversation |
|
Help center |
|
Search help |
|
Ask AI a question |
|
One help article |
|
What's new (changelog) |
|
The article id is the 10 characters after /articles/ in the article's web address.
To put the messenger, the help center or the changelog inside your own layout (a tab, say), use Agent44.embedded(.helpCenter) as a SwiftUI view.
Update prompts and What's New#
No extra code needed. Create these in agent44 under Engagement, and the SDK shows them when the app opens:
Force update: a full screen the user can't close until they update. Contact support under its button opens the chat over it.
Recommended update: a sheet asking them to update, which they can skip.
What's New: shown once after the user updates, with your changelog entry.
Announcements, banners and chat messages: for news and offers.
Only the most important one shows each time the app opens. The SDK sends the device's iOS version with each check, so a phone too old for the new build (its Minimum system in agent44) isn't locked out.
To choose when they show, pass showInAppMessages: false to configure and call await Agent44.checkInAppMessages() yourself. To draw a message yourself, pass onInAppMessage: { message in … return true } and report what happened with await Agent44.client?.engagement.track(message.id, .clicked) (.shown, .clicked or .dismissed).
Push notifications (optional)#
With push, users get a notification when your team or the AI agent replies (tapping it opens the conversation), and you can send push campaigns from agent44's Engagement. agent44 sends straight to Apple (APNs).
1. In agent44: open Settings › Apps, pick the iOS app and set up Push notifications with your APNs key (the .p8 file from Apple Developer › Keys, with its Key ID and your Team ID).
2. In your app: add the Push Notifications capability, then:
final class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions …) -> Bool {
Agent44.configure(publicKey: "a44_pub_…")
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, _ in
if granted { DispatchQueue.main.async { application.registerForRemoteNotifications() } }
}
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Task { await Agent44.setPushToken(deviceToken) }
}
// A tap: a reply opens its conversation, a campaign opens its link.
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async {
await MainActor.run { _ = Agent44.handle(response) }
}
// While the app is open: keeps the badge and the open conversation up to date.
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions {
await MainActor.run { Agent44.presentationOptions(for: notification) }
}
}(SwiftUI apps: @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate.)
Good to know:
setPushTokensends thesandboxenvironment in debug builds andproductionotherwise; passsandbox:to override (a debug build distributed through TestFlight, say). Passenabled: falsewhen the user turned notifications off.A tap that launched the app waits for the SDK and a window, up to 30 seconds, so it's fine to call
handlebefore your UI is up. It's dropped if the user signs out first.Campaign links can be an
https://page or your own deep link (withdeepLinkSchemes). PassopenURL:tohandleto route links yourself.Using Firebase Messaging or another library? Pass the APNs token (not the FCM token) to
setPushToken, and each notification'suserInfotohandlePushTap/handleForegroundPush.Agent44.logout()stops that user's notifications on the device.
Not yet in this version#
Compared with the Flutter SDK, 0.1.0 doesn't have these yet:
A tablet layout. On iPad the screens use the phone layout, full width; there's no two-column layout with a side rail.
Videos inside help content. A YouTube, Vimeo or Loom embed shows its thumbnail and opens the video in the browser instead of playing in the article.
Article page storage. Help articles open in a web view with non-persistent storage, so anything the page stores (its own preferences, say) resets each time an article opens.
Translated VoiceOver labels on a few buttons. "Back", "Close", "Dismiss" and "Remove " are English only; every other text comes from
Agent44Strings.