简单而现代的客户支持平台,旨在尽可能地方便。几分钟即可开始使用。
Chat2App 是 Chat2App 实时客户聊天平台的客户端。它是 100% Swift
编写的。
平台 | 最低目标 |
---|---|
iOS | 15.0+ |
在此注册一个新的 Chat2App 帐户。
点击“添加新应用”按钮,在此填写添加新应用的表单
启用推送通知,让您的用户了解新消息。此设置不是必需的。
在您的 AppDelegate.swift
中配置 SDK,以便能够在您的整个项目中使用 Chat2App。
import Chat2App
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Chat2App.shared.setApiKeyForAppId(apiKey: <chat2app_api_key>, appId: <chat2app_app_id>)
Chat2App.shared.operatorName = "<Operator name>"
Chat2App.shared.firstMessageText = "<First message text>"
}
推送通知是与用户互动的一个强大工具,但您使用它们的方式应根据您的具体业务需求进行调整。 此示例显示了如何在 AppDelegate.swift
中的应用程序启动后立即设置推送通知的权限请求。
import Chat2App
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Chat2App.shared.setApiKeyForAppId(apiKey: <chat2app_api_key>, appId: <chat2app_app_id>)
Chat2App.shared.operatorName = "<Operator name>"
Chat2App.shared.firstMessageText = "<First message text>"
self.registerForPushNotifications()
}
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Chat2App.shared.apnsToken = deviceToken
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
Chat2App.shared.handlePushNotification(userInfo: userInfo)
}
func registerForPushNotifications() {
Task(priority: .high) { [weak self] in
do {
let granted = try await UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge])
print("granted = \(granted)")
if granted == true {
DispatchQueue.main.async {
self?.getNotificationSettings()
}
}
} catch {
print(error)
}
}
}
func getNotificationSettings() {
UNUserNotificationCenter.current().getNotificationSettings { settings in
print("Notification settings: \(settings)")
guard settings.authorizationStatus == .authorized else { return }
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}
通过指定聊天用户的姓名、唯一标识符和一组附加数据来配置聊天用户。
Chat2App.shared.setChatUser(name: ""<User name>"", uniqId: ""<uniq id>"", userData: ["foo":"bar"])
NSUbiquitousKeyValueStore
中,以便在所有设备上都可以使用相同的聊天。Chat2App.shared.presentMessenger(from: self)
Task {
await Chat2App.shared.addMessageFromOperator(text: "Your message")
}
为了回复用户消息,请从 Appstore 下载 Chat2App 应用。