适用于 iOS 应用的最佳实时客户聊天平台

SwiftPM compatible

简单而现代的客户支持平台,旨在尽可能地方便。几分钟即可开始使用。

注册以免费开始使用

Chat2App.framework

Chat2AppChat2App 实时客户聊天平台的客户端。它是 100% Swift 编写的。

要求

平台 最低目标
iOS 15.0+

用例

chat2appExampleFinal.mp4

快速入门指南

1. 创建 Chat2App 帐户

在此注册一个新的 Chat2App 帐户。

2. 添加您的应用

点击“添加新应用”按钮,在此填写添加新应用的表单

3. 设置 Apple 推送通知设置

启用推送通知,让您的用户了解新消息。此设置不是必需的。

4. 通过 Swift Package Manager 安装 Chat2App SDK

  1. 在 Xcode 中,选择“文件”>“Swift Packages”>“添加 Package Dependency”。
  2. 使用此存储库的 URL 按照提示操作。

5. 配置 SDK

在您的 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>"
}

6. 配置 Apple 推送通知

推送通知是与用户互动的一个强大工具,但您使用它们的方式应根据您的具体业务需求进行调整。 此示例显示了如何在 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()
            }
        }
    }

7. 聊天用户配置

通过指定聊天用户的姓名、唯一标识符和一组附加数据来配置聊天用户。

Chat2App.shared.setChatUser(name: ""<User name>"", uniqId: ""<uniq id>"", userData: ["foo":"bar"])

8. 显示聊天

Chat2App.shared.presentMessenger(from: self)

9. 以操作员身份发送消息

Task {
    await Chat2App.shared.addMessageFromOperator(text: "Your message")
}

下载 Chat2App 应用

为了回复用户消息,请从 Appstore 下载 Chat2App 应用。