推送通知

您可以使用Chat SDK的推送通知,在每次代理向对话发送新消息时通知您的用户。

请注意:如果您的帐户正在使用代理工作区,您将不会收到聊天会话结束的通知。这是由于会话的终止不同。我们建议您的代理在关闭聊天前发送消息,以避免不知情的终止。

在Zendesk聊天仪表板中设置推送通知亚博

要在Chat仪表板中设置推送通知,请按照的指导方针在聊天帮助中心。启用推送通知后,集成商将需要聊天帐户密钥和appID。这些被传递到聊天初始化代码中:

斯威夫特

             
进口ChatSDK进口ChatProvidersSDK闲谈,聊天在itialize(accountKey: <#"Your account key"#>, appId: <#Your app identifier#>)

objective - c

             
进口<ChatSDK/ChatSDKh>进口<ChatProvidersSDK/ChatProvidersSDKh>ZDKChat initializeWithAccountKey<“您的帐号密码”>appId<#您的应用程序标识符#>队列dispatch_get_main_queue]

配置Apple推送通知服务

有关如何为Apple的推送通知服务生成。pem文件的说明,请参见为聊天SDK启用iOS推送通知

当应用程序处于后台模式时启用推送通知

本节概述启用推送通知的步骤。当应用程序处于后台模式且聊天处于断开状态时,就会发送推送通知。如果您使用的是开箱即用的UI,那么只要用户不在聊天视图中,聊天就会断开。有关应用内通知,请参见在应用中启用应用内推送通知

1.向用户请求推送通知的授权

使用注册推送通知UNUserNotificationCenter在你的AppDelegate中(只针对设备)。参见设置聊天SDK的应用内推送通知下面实现UNUserNotificationCenter

斯威夫特

             
进口UserNotifications#如果! TARGET_IPHONE_SIMULATORlet notificationCenter = UNUserNotificationCenter.current()notificationCenter.delegate = selfnotificationCenter。requestAuthorization(选项:[。Alert, .sound, .badge]){granted, _ inGuard授予else {return}DispatchQueue.main.async {UIApplication.shared.registerForRemoteNotifications ()# endif

objective - c

             
进口<UserNotifications/UserNotificationsh>进口<ChatProvidersSDK/ChatProvidersSDKh>如果TARGET_IPHONE_SIMULATORUNUserNotificationCenter*中心=UNUserNotificationCenter currentNotificationCenter]中心委托=自我中心requestAuthorizationWithOptionsUNAuthorizationOptionSound|UNAuthorizationOptionAlert|UNAuthorizationOptionBadgecompletionHandlerBOOL授予NSError*_Nullable错误{如果错误{UIApplication sharedApplication]registerForRemoteNotifications]]endif
2.在聊天SDK中注册接收到的设备令牌

覆盖函数application (_application: UIApplication, didreregisterforremotenotificationswithdevicetoken deviceToken: Data)在你的AppDelegate

斯威夫特

             
进口ChatProvidersSDK函数application(_ application: UIApplication, didreregisterforremotenotifationswithdevicetoken deviceToken: Data) {Chat.registerPushToken (deviceToken)

objective - c

             
进口<ChatProvidersSDK/ChatProvidersSDKh>-无效应用程序UIApplication*应用didRegisterForRemoteNotificationsWithDeviceTokenNSData*deviceToken{ZDKChat registerPushTokendeviceToken]

3.将接收到的远程推送通知传递给聊天SDK

斯威夫特

             
进口ChatProvidersSDKUNUserNotificationCenter: UNUserNotificationCenterdidReceive response: UNNotificationResponse,withCompletionHandler completionHandler: @escaping () -> Void) {let userInfo = response.notification.request.content.userInfolet application = UIApplication.shared闲谈,聊天didReceiveRemoteNotification(userInfo, in: application)completionHandler ()

objective - c

             
进口<ChatProvidersSDK/ChatProvidersSDKh>-无效userNotificationCenterUNUserNotificationCenter*中心didReceiveNotificationResponseUNNotificationResponse*响应withCompletionHandler无效completionHandler{ZDKChat didReceiveRemoteNotification用户信息应用程序]completionHandler

在应用中启用应用内推送通知

允许通知在你的应用中显示UNUserNotificationCenterDelegate方法。

斯威夫特

             
进口UserNotificationsUNUserNotificationCenter: UNUserNotificationCenterwillPresent notification: UNNotification,withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {completionHandler([。Alert, .sound, .badge])

objective - c

             
进口<UserNotifications/UserNotificationsh>//在AppDelegate.h中使AppDelegate符合UNUserNotificationCenterDelegate@ interfaceAppDelegateUIResponder<UIApplicationDelegateUNUserNotificationCenterDelegate>-无效userNotificationCenterUNUserNotificationCenter*中心willPresentNotificationUNNotification*通知withCompletionHandler无效UNNotificationPresentationOptions选项completionHandler{completionHandlerUNNotificationPresentationOptionAlert|UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge

推送通知的类型

Chat SDK支持两种类型的推送通知:

  • 新增聊天消息通知
  • 聊天结束通知
新增聊天消息通知
             
{“aps”{“警告”{“标题”“{代理名称}”“身体”“{代理消息}”“数据”{“类型”“zd.chat.msg”“t”"{毫秒时间戳(长)}"
聊天结束通知
             
{“aps”{“警告”{“title-loc-key”“ios.ZDCChat.pushChatEndedTitle”“loc-key”“ios.ZDCChat.pushChatEndedBody”“loc-args”“{代理名称}”]“数据”{“类型”“zd.chat.end”“t”"{毫秒时间戳(长)}"

请注意:如果您的帐户正在使用代理工作区,您将不会收到聊天会话结束的通知。这是由于会话的终止不同。我们建议您的代理在关闭聊天前发送消息,以避免不知情的终止。

识别收到的推送通知

聊天SDK允许您识别Zendesk发送的推送通知亚博PushNotificationProvider

识别聊天SDK推送通知

斯威夫特

             
进口ChatProvidersSDKUNUserNotificationCenter: UNUserNotificationCenterdidReceive response: UNNotificationResponse,withCompletionHandler completionHandler: @escaping () -> Void) {.isChatPushNotification(userInfo) {//处理聊天发送的推送通知

objective - c

             
进口<ChatProvidersSDK/ChatProvidersSDKh>-无效userNotificationCenterUNUserNotificationCenter*中心didReceiveNotificationResponseUNNotificationResponse*响应withCompletionHandler无效completionHandler{如果ZDKChatpushNotificationsProvider isChatPushNotification用户信息]{//处理聊天发送的推送通知

识别推送通知的类型

此外,您可以利用类型安全PushNotificationData类来推断推送通知的类型。

斯威夫特

             
进口ChatProvidersSDKUNUserNotificationCenter: UNUserNotificationCenterdidReceive response: UNNotificationResponse,withCompletionHandler completionHandler: @escaping () -> Void) {let pushNotificationData = pushNotificationData。数据(用户信息):开关pushNotificationData ?。类型{案例.message://收到消息通知案例.chatEnded://收到聊天结束通知

objective - c

             
进口<ChatProvidersSDK/ChatProvidersSDKh>-无效userNotificationCenterUNUserNotificationCenter*中心didReceiveNotificationResponseUNNotificationResponse*响应withCompletionHandler无效completionHandler{ZDKPushNotificationData*数据=ZDKPushNotificationData dataFor用户信息]如果数据! ={开关数据类型{情况下ZDKPushNotificationTypeMessage//收到消息通知打破情况下ZDKPushNotificationTypeChatEnded//收到聊天结束通知打破默认的打破

本地化推送通知

要了解如何本地化Chat SDK的推送通知,请参阅统一SDK文档