Hippo 2.1.58

Hippo 2.1.58

由以下人员维护:ArohiJungleworksGian SinghVishal jhanjhriGoldenRahul vermakranthi kumar



Hippo 2.1.58

  • 作者
  • Vishal Jhanjhri

HippoChat iOS SDK

安装HippoChat以查看和与您的iPhone应用程序用户交谈。HippoChat SDK通过CocoaPods进行分发。以下是对此方法的说明

先决条件

  1. Hippo SDK支持iOS 11.0及以上版本
  2. Hippo App_Secret_Key/Reseller_token
  3. Xcode

在集成过程中,如果您有任何疑问,请联系我们:[email protected]

第1步:使用CocoaPods安装

HippoChat通过CocoaPods提供。要将HippoChat添加到您的项目,请按照以下示例将SDK添加到您的Podfile中。

  • 如果您想在不调用或想要使用jitsi calling的情况下使用Hippo,以及添加以下行到您的项目podfile中:pod 'Hippo', :git => 'https://github.com/Jungle-Works/Hippo-iOS-SDK', :branch => 'master'

  • 如果您想使用带有Video sdk calling的Hippo,请向您的项目podfile中添加以下行:pod 'Hippo', :git => 'https://github.com/Jungle-Works/Hippo-iOS-SDK', :branch => 'VideoSDKRelease'

更新您的Podfile后,运行pod install(终端命令),以自动将SDK下载并安装到您的项目中。

请注意:HippoChat SDK支持针对iOS 10.0+的应用。SDK本身与所有上述iOS 10.0+兼容

升级HippoChat SDK?

在您的项目目录中运行pod update Hippo(终端命令)。

注意:当使用Call SDK时,Hippo不支持bitcode,要继续使用Hippo,请在App Target设置中禁用bitcode,即app_target > Build Settings > Enable Bitcode > No

注意:使用Hippo需要的权限有: Privacy - Camera Usage Description, Privacy - Microphone Usage Description, Privacy - Photo Library Additions Usage Description, Privacy - Photo Library Usage Description。将这些权限添加到info.plist中,以避免崩溃。

注意:在Hippo中添加“Background modes”功能:Hippo ->> Signing and Capabilities tab,并启用远程通知、VoIP、音频/图片拼接

第二步:添加HippoChat凭证

在您的项目中添加SDK后,在调用/尝试使用Hippo SDK的其他功能/方法之前,请添加HippoChat凭证。

HippoChat凭证可通过APP-SECRET-KEYRESELLER-TOKEN和REFERENCE-ID添加。下面将详细介绍这两种方法。

选项A - 通过YOUR-APP-SECRET-KEY添加凭证

以下列出了添加凭证的常用方法。

HippoConfig.shared.setCredential(withAppSecretKey: YOUR-APP-SECRET-KEY)

如果您打算使用来自同一APP-SECRET-KEY的多个应用程序,您必须在仪表板上添加您的应用程序,这将生成一个APP-TYPE,您将使用它来设置凭证。使用同一APP-SECRET-KEY生成的不同应用程序将具有不同的APP-TYPE。

HippoConfig.shared.setCredential(withAppSecretKey: YOUR-APP-SECRET-KEY, appType: YOUR-APP-TYPE)

注意:我们强烈建议您只添加一次凭证,并在您应用的目标AppDelegate's application:didFinishLaunchingWithOptions:或登录应用程序时添加。不要忘记将以下代码片段中的YOUR-APP-SECRET-KEY替换为实际的应用程序密钥。

func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) -> Bool {
...
HippoConfig.shared.setCredential(withAppSecretKey: YOUR-APP-SECRET-KEY)
...
}

注意:如果您想将应用程序名称设置在自定义推送通知中,请使用以下方法添加您的Hippo凭证。

HippoConfig.shared.setAppName(withAppName: YOUR-APPNAME)

B选项 - 通过您的“经销商令牌”、“参考ID”和“应用程序类型”添加凭证

在调用/尝试使用Hippo SDK的任何其他功能/方法之前,通过您的reseller_tokenrefernce_id密钥添加凭证。如下文所述

HippoConfig.shared.setCredential(withToken: YOUR-RESELLER-TOKEN,
referenceId: YOUR-REFERENCE-ID,
appType: YOUR-APP-TYPE)

注意:我们强烈建议只添加一次凭证,并从您的AppDelegate的application:didFinishLaunchingWithOptions:方法中添加。不要忘记以下代码片段中的YOUR-RESELLER-TOKENYOUR-REFERENCE-IDYOUR-APP-TYPE替换为实际的经销商令牌、参考ID和应用类型。

func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) -> Bool {
...
HippoConfig.shared.setCredential(withToken: YOUR-RESELLER-TOKEN,
referenceId: YOUR-REFERENCE-ID,
appType: YOUR-APP-TYPE)
...
}

第3步:更新用户信息

通过传递用户数据更新或编辑服务器上的用户配置文件,更新或登录用户信息,例如这样

//Get the user object for the current installation (for customers)
let HippoUserDetail = HippoUserDetail(fullName: "<Full_name_string>",
email: "<Email_string>",
phoneNumber: "<phone_number_string>",
userUniqueKey: "<your_unique_identifier_for_user>",
addressAttribute: <initialize_HippoAttributes>,
customAttributes: <set_custom_attributes>,
selectedlanguage: <selected_language>
)

//Call updateUserDetails so that
//the user information is synced with Hippo servers 
HippoConfig.shared.updateUserDetail(userDetail: HippoUserDetail)
HippoConfig.shared.setCredential(withAppSecretKey: YOUR-APP-SECRET-KEY, appType: YOUR-APP-TYPE)

//For initialization of Hippo Manager
  HippoConfig.shared.initManager(authToken: "<User_auth_Token>", 
  app_type: "<App_Type>", 
  selectedLanguage: <selected_language>)

-> for video sdk implementation also pass (appSecretKey: YOUR-APP-SECRET-KEY) in the same function initManager

注意:如果您在此处没有可用的唯一用户标识符,或者如果您有一个userId和一个电子邮件,您可以在注册对象上使用电子邮件/电话号码作为唯一的键。

第4步:在您的应用内显示对话

针对特定的UI事件,如菜单选择或按钮点击事件,调用presentChatsViewController()方法启动对话流程。如果应用配置了多个频道,用户将看到频道列表。当没有消息时,频道列表按仪表板上指定的顺序排列。

// Launching Conversation List in your app screen
HippoConfig.shared.presentChatsViewController()

第5步:处理推送通知

通过 Hippo 启用推送通知的步骤

  1. 将设备注册令牌发送给 Hippo
  2. 自定义通知外观和传递通知数据给 Hippo
  3. 处理推送通知点击

1: 将设备注册令牌发送给 Hippo

HippoChat 使用 SDK 可以发送推送通知给您的用户。为了启用此支持,当您的应用程序代理接收到 application:didRegisterForRemoteNotificationsWithDeviceToken: 方法时,请包含对以下 registerDeviceToken(deviceToken: Data) 方法的调用

func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
HippoConfig.shared.registerDeviceToken(deviceToken: deviceToken)
}

2: 自定义通知外观和传递通知数据给 Hippo

接收到远程通知后,将远程通知的 userInfo 传递到 isHippoNotification(withUserInfo: pushInfo)showNotification(userInfo: pushInfo) 方法中,如以下所述,以验证 Hippo 通知

func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
let pushInfo = (userInfo as? [String : Any]) ?? [:]
if HippoConfig.shared.isHippoNotification(withUserInfo: pushInfo) {

if HippoConfig.shared.showNotification(userInfo: pushInfo) {
...
//setup banner or any UI you want to show inside your app
//and call `HippoConfig.shared.handleRemoteNotification(userInfo: pushInfo)`
//after tapping on that banner
...
}
return
} 
}

第6步:登出时清除用户数据

通过调用 clearHippoUserData() 函数,在用户登出或在根据用户在应用程序中的操作适当时清除用户数据

HippoConfig.shared.clearHippoUserData()

高级功能

其他信息代理

将 "HippoDelegate" 继承到类中,并将其设置为 HippoConfig.shared.setHippoDelegate(delegate: <-您的类>),这将在任何信息或任何可用的消息上通知该类。此代理还用于获取视图中调用和音频调用的视图。

HippoConfig.shared.setHippoDelegate(delegate: <HippoDelegate>)

使用 channelID 打开特定的聊天

针对特定的 UI 事件(如菜单选择或按钮点击事件),调用 openChatWith(channelId: Int, completion: (_ success: Bool, _ error: Error?) -> Void) 方法,通过传递以下提到的 Channel-ID 打开指定的频道。

// Launching Conversation List from click of a button in your app's screen
HippoConfig.shared.openChatWith(channelId: CHANNEL_ID, completion: { (success, error) in
// handle success or error
})

在特定交易上打开唯一的聊天

如果您想通过特定的交易打开唯一的频道(例如,如果您想打开与特定订单对应的聊天),可以调用 openChatScreen(withTransactionId transactionId: String, tags: [String]? = nil, channelName: String, message: String = "", userUniqueKey: String? = nil, completion: @escaping (_ success: Bool, _ error: Error?) -> Void) 方法。

// Launching Conversation List from click of a button in your iOS app
/**
- parameter withTransactionId: Unique ID to recognize your chat, ex. your OrderID
- parameter tags: Additional Information which will be user to distinguis chats in Dashboard
- parameter channelName: If you want to specify a name for the chat, or you can leave it empty 
- parameter message: Optional parameter, if you want to start a chat with a first message already added
HippoConfig.shared.openChatScreen(withTransactionId: "<transation_id>",
tags: ["<tag_1>, <tag_2>"],
channelName: "<channel_name>", message: "First message after opening the chat")

打开点对点聊天

使用 HippoConfig.shared.showPeerChatWith(data: PeerToPeerChat, completion: @escaping (_ success: Bool, _ error: Error?) -> Void) 打开与对方的聊天屏幕。

/**
- parameter uniqueChatId: Unique ID you will use to recognize seprate chats between same peers. Could be set to `nil` if there is no need to create seprate chat between same peers.
- parameter myUniqueId: ID which your systems uses to recognize you uniquely.
- parameter idsOfPeers: Unique IDs of peers with whom you want to start chat.
- parameter channelName: Name you want to give your chat, If you want peers name to show pass empty string.
*/
let peerChatInfo = PeerToPeerChat(uniqueChatId: "YOUR-UNIQUE-CHAT-ID", myUniqueId: "YOUR-UNIQUE-ID", idsOfPeers: ["PEER-UNIQUE-ID"], channelName: "CHANNEL-NAME")

HippoConfig.shared.showPeerChatWith(data: peerChatInfo, completion: { (success, error) in
//handle success or error
})

在开发和生产环境之间切换

使用HippoConfig.shared.switchEnvironment(_ envType: HippoEnvironment)在开发和Live环境之间切换

HippoConfig.shared.switchEnvironment(.dev)

或者

HippoConfig.shared.switchEnvironment(.live)

live为默认选择。

修改Hippo Chat屏幕的颜色,以匹配您应用程序的视觉和感觉

使用HippoConfig.shared.setCustomisedHippoTheme(theme: HippoTheme)方法轻松地在Hippo屏幕中重现您应用程序的外观和感觉,参考代码片段如下

我们强烈建议只在AppDelegate的application:didFinishLaunchingWithOptions方法中添加一次凭证。

func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject:AnyObject]?) -> Bool {
...
let hippotheme = HippoTheme.defaultTheme()
hippotheme.backgroundColor = .black
hippotheme.headerBackgroundColor = .black
hippotheme.headerTextColor = .black
hippotheme.headerText = "support"
hippotheme.promotionsAnnouncementsHeaderText = "Announcements"

HippoConfig.shared.setCustomisedHippoTheme(theme: hippotheme)
...
}

与Hippo Theme传递字体

使用HippoTheme.defaultTheme(fontRegular: "", fontBold: ")将您的应用程序字体传递到Hippo Theme

/**
- parameter fontRegular: Pass app regular font here
fontBold: Pass app Bold/Semi-Bold font here
*/

多语言支持

使用HippoConfig.shared.setLanguage(_ code : String)从您的应用程序中传递选定的语言代码以使用特定语言

/**
- parameter code: Pass language code here. For example: "en" for English or "es" For Spanish
*/

初始化Bot(管理员不可用)

使用HippoConfig.shared.setNewConversationBotGroupId(botGroupId:)传递您的botgroupid

公告部分(管理员不可用)

使用HippoConfig.shared.presentPromotionalPushController()从您的应用程序中打开公告部分

为Hippo SDK设置音频/视频通话

要启用Hippo SDK中的音频/视频通话,请从Hippo仪表板设置 > 插件 > 音频/视频通话启用它

注意:请参阅其他信息代理段落,单击此处,因为您需要在应用程序视图中发送视频通话/音频通话。

1: 安装Call SDK

安装视频和音频通话的Call SubPod。

  • 如果您想在不进行通话的情况下使用Hippo,或者想使用Jitsi进行通话,请将以下行添加到您的项目pod文件中:pod 'Hippo/Call', :git => 'https://github.com/Jungle-Works/Hippo-iOS-SDK', :branch => 'master'

  • 如果您想使用带有视频SDK的Hippo进行通话,请将以下行添加到您的项目pod文件中:pod 'Hippo/Call', :git => 'https://github.com/Jungle-Works/Hippo-iOS-SDK', :branch => 'VideoSDKRelease'

更新您的Podfile后,运行pod install(终端命令),以自动将SDK下载并安装到您的项目中。

2: 首先在您的应用代理中注册VOIP通知

您可以参考以下链接。如果已注册,请继续下一步https://medium.com/ios-expert-series-or-interview-series/voip-push-notifications-using-ios-pushkit-5bc4a8f4d587

3: 发送VOIP设备注册令牌

HippoChat使用SDK能够向您的用户发送推送通知。要启用此支持,当您的应用代理接收 _ registry: PKPushRegistry,didUpdate pushCredentials: PKPushCredentials,for type: PKPushType 方法时,请包含对以下 registerVoipDeviceToken(deviceToken: Data) 的调用

func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
let token = pushCredentials.token
HippoConfig.shared.registerVoipDeviceToken(deviceData: token)
}

4: 将Voip通知数据传递给Hippo SDK

接收到Voip通知后,将remoteNotification userInfo传递给isHippoNotification(withUserInfo: pushInfo)和showNotification(userInfo: pushInfo)方法,以验证Hippo通知,具体如下。

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
guard type == PKPushType.voIP else {
return
}
if HippoConfig.shared.isHippoNotification(withUserInfo: pushInfo) {
HippoConfig.shared.handleVoipNotification(payloadDict: payload.dictionaryPayload)
} else {
//Its your voip push to handle
}
}

5: 启动点对点视频聊天

使用HippoConfig.shared.startVideoCall(data: PeerToPeerChat, completion: @escaping (_ success: Bool, _ error: Error?) -> Void)打开聊天界面。

/**
- parameter uniqueChatId: Unique ID you will use to recognize seprate chats between same peers. Could be set to `nil` if there is no need to create seprate chat between same peers.
- parameter myUniqueId: ID which your systems uses to recognize you uniquely.
- parameter idsOfPeers: Unique IDs of peers with whom you want to start chat.
- parameter channelName: Name you want to give your chat, If you want peers name to show pass empty string.
- parameter peerName: Other peer name to show on screen.
*/
let peerChatInfo = PeerToPeerChat(uniqueChatId: "YOUR-UNIQUE-CHAT-ID", myUniqueId: "YOUR-UNIQUE-ID", idsOfPeers: ["PEER-UNIQUE-ID"], channelName: "CHANNEL-NAME", peerName: "Peer name")


HippoConfig.shared.startVideoCall(data: peerChatInfo, callType: .(audio/video), completion: { (success, error) in
//handle success or error
})
  1. 在安装Hippo call客户端pod后,选择项目根目录下的pods,在项目名称下方。
  2. 在目标中,选择HippoCallClient(蓝色选项),在构建阶段选择复制资源包,点击+图标,并添加VideoSDK.storyboard和ButtonControlsView.xib。

设置高级统计数据更新

要启用高级统计信息的更新,当用户点击通知和用户在应用中花费的时间时,您必须将以下代码添加到您的项目AppDelegate文件。

在AppDelegate文件中找到didFinishLaunchWithOptions,添加代码:if let lauchOptionInfo = launchOptions, let remoteNotification = lauchOptionInfo[UIApplication.LaunchOptionsKey.remoteNotification] as? [String: Any] { userInfo = remoteNotification

        if (remoteNotification["is_announcement_push"] as? Int != nil && remoteNotification["is_announcement_push"] as? Int == 1) || (remoteNotification["channel_type"] as? Int != nil && remoteNotification["channel_type"] as? Int == 6) {
            openendFromPush = true
            DispatchQueue.main.asyncAfter(deadline: .now() + 1.7) {
                ChatSDK.shared.handelPush(userInfo: remoteNotification)
            }
        }
    }

在AppDelegate文件中添加此函数:func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

    if openendFromPush || (UIApplication.shared.applicationState != .background && UIApplication.shared.applicationState != .active){
        openendFromPush = false
        return
    }
    
    if let userInfo = userInfo as? [String : Any]{
        HippoConfig.shared.managePromotionOrP2pCount(userInfo)
        HippoConfig.shared.callMissedFromUser(userInfo: userInfo)
        
        completionHandler(UIBackgroundFetchResult.newData)
    }else{
        completionHandler(UIBackgroundFetchResult.failed)
    }
}

在didReceiveResponse中添加:if HippoConfig.shared.isHippoNotification(withUserInfo: userInfo) { HippoConfig.shared.handleRemoteNotification(userInfo: userInfo) }

在AppDelegate中添加此函数以更新会话时间到后端:func applicationWillResignActive(_ application: UIApplication) { HippoConfig.shared.hitStatsApi(userInfo: nil, sendSessionTym: true) }

要在您的应用中任何屏幕上显示推广弹出窗口,并在按钮点击时接收数据,请添加以下代码:HippoConfig.shared.presentPromotionalPopUp(on: Your_View_Controller) { data in print("Button one call back received with (data)") } onButtonTwoClick: { data in print("Button two call back received with (data)") }

点击机器人按钮以接收回调

要接收点击按钮的数据回调,请添加以下代码 - HippoConfig.shared.botButtonActionCallBack = { [weak self] (data) in

}