迁移向导

从经典SDK迁移到Zendesk SDK亚博

的经典SDK更新开始消息传递5.3.0,我们改进了与Zendesk SDK的兼容性,以便更容易地从经典SDK迁移亚博到Zendesk SDK。

只有版本的经典SDK使用消息传递5.3.0和向前的迁徙是兼容的。

一些功能需要额外的步骤,以便在使用经典和Zendesk SDK时正常工作。亚博

聊天SDK和Zendesk SDK在同一应用程序的推送通知亚博

以下步骤将指导您或您的开发团队在同一应用程序中为Chat SDK和Zendesk SDK设置推送通知。亚博

步骤1 -在Firebase中设置推送通知

在应用程序中设置Firebase云消息传递所以你的应用程序能够接收来自Firebase的推送通知。

你还必须设置Zendesk侧配置,如下所示:亚博

步骤2 -在应用程序中为Zendesk SDK和Chat SDK创建Firebase服务亚博

为了同时接收两个SDK的推送通知,你必须为每个SDK创建一个服务。下面的代码片段演示了如何为每个SDK创建服务。

请注意:此实现不适用于默认Zendes亚博k SDK Push

的代码片段亚博Zendesk SDK Push服务

亚博ZendeskSDKFirebaseMessagingService

             
进口com.google.firebase.messaging.FirebaseMessagingService进口com.google.firebase.messaging.RemoteMessage进口zende亚博sk.logger.Logger进口zende亚博sk.messaging.android.push.PushNotifications进口zende亚博sk.messaging.android.push.PushResponsibility类Zende亚博skSDKFirebaseMessagingService: FirebaseMessagingService() {重载onmessagerreceived (remoteMessage: remoteMessage) {记录器。d(LOG_TAG, "Received new FCM push: %s", remoteMessage.data)当(pushnotification . shouldbedisplay (remoteMessage.data)) {PushResponsibility。Messaging_should_display -> {//此推送属于消息传递,SDK能够将其显示给最终用户记录器。d(LOG_TAG, " onmessagerreceived: MESSAGING_SHOULD_DISPLAY")PushNotifications。displayNotification(context = this, messageData = remoteMessage.data)}PushResponsibility。Messaging_should_not_display -> {//此推送属于消息传递,但不应该显示给最终用户记录器。d(LOG_TAG, " onmessagerreceived: MESSAGING_SHOULD_NOT_DISPLAY")}PushResponsibility。Not_from_messaging -> {//此推送不属于消息传递记录器。d(LOG_TAG, " onmessagerreceived: NOT_FROM_MESSAGING")}}}重载onNewToken(newToken: String) {记录器。d(LOG_TAG, "刷新的token: %s", newToken)PushNotifications.updatePushNotificationToken (newToken)}私有伴侣对象{const val LOG_TAG = "亚博ZendeskSDKFirebaseMessagingService"}}

的代码片段经典聊天SDK推送服务

ChatSDKFirebaseMessagingService

             
进口android.app.Notification进口android.app.NotificationChannel进口android.app.NotificationManager进口android.app.PendingIntent进口android.content.Context进口android.os.Build进口androidx.core.app.NotificationCompat进口com.google.firebase.messaging.FirebaseMessaging进口com.google.firebase.messaging.FirebaseMessagingService进口com.google.firebase.messaging.RemoteMessage进口com.zende亚博sk.logger.Logger进口com.zende亚博sk.service.ErrorResponse进口com.zende亚博sk.service.ZendeskCallback进口zende亚博sk.chat.Chat进口zende亚博sk.chat.ChatConfiguration进口zende亚博sk.chat.ChatEngine进口zende亚博sk.chat.PushData进口zende亚博sk.classic.messaging.MessagingActivity进口zende亚博sk.sample.sdksintegration.R类ChatSDKFirebaseMessagingService: FirebaseMessagingService() {重载onNewToken(token: String) {记录器。d(LOG_TAG, "刷新令牌:%s",令牌)}重载onmessagerreceived (remoteMessage: remoteMessage) {super.onMessageReceived (remoteMessage)记录器。d(LOG_TAG, "Message received: %s", remoteMessage.data)handleChatPushData (remoteMessage)}private fun handleChatPushData(remoteMessage: remoteMessage) {val pushNotificationsProvider = Chat.INSTANCE.providers()?if (pushNotificationsProvider == null) {记录器。e(LOG_TAG, "聊天未初始化,无法处理收到的消息")返回}pushNotificationsProvider.processPushNotification (remoteMessage.data) ?。let {pushData ->当(pushData.type) {PushData.Type.MESSAGE -> pushData.message?let {showNotification(it)}PushData.Type.END -> showNotification("Session已经结束")}}}private fun showNotification(contentText: String, contentTitle: String = SOURCE_CHAT) {val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as notificationManagerval channelId = applicationContext.亚博电脑端resources.getString(r.s estring .app_name)val pendingIntent = setOpenNotificationIntent()createNotificationChannel (notificationManager channelId)val notification = NotificationCompat。构建器(applicationContext, channelId).setSmallIcon (R.drawable.ic_expand_more).setDefaults (Notification.DEFAULT_ALL).setContentTitle (contentTitle).setContentText (contentText).setContentIntent (pendingIntent).setAutoCancel(真正的).build ()notificationManager。通知(NOTIFICATION_ID、通知)}/ * **设置[PendingIntent]在通知被点击时触发。** @返回[MessagingActivity]的意图,如果它存在,意图午餐代替。* /private fun setOpenNotificationIntent(): PendingIntent {val chatConfiguration = chatConfiguration .builder().withAgentAvailabilityEnabled(假).build ()val messagingActivity = messagingActivity .builder().withEngines (ChatEngine.engine ())chatConfiguration .intent(这): packageManager.getLaunchIntentForPackage(packageName)val flags = if (Build.VERSION.)SDK_INT > Build.VERSION_CODES.R) {PendingIntent。FLAG_ONE_SHOTor PendingIntent.FLAG_IMMUTABLE} else {PendingIntent。FLAG_ONE_SHOT}返回PendingIntent.getActivity (这一点,INTENT_REQUEST_CODE,intentToLaunch,旗帜}private fun createNotificationChannel(notificationManager: notificationManager, channelId: String) {如果(Build.VERSION。SDK_INT >= Build.VERSION_CODES.O) {val name = getString(r.t rstring .app_name)val重要性= NotificationManager。IMPORTANCE_HIGHval channel = NotificationChannel(channelId, name, importance)notificationManager.createNotificationChannel(频道)}}伴侣对象{private const val LOG_TAG = "ChatSDKFirebaseMessagingService"private const val NOTIFICATION_ID = 12345private const val INTENT_REQUEST_CODE = 0private const val SOURCE_CHAT = "Chat"Fun init() {.token FirebaseMessaging.getInstance()。addOnCompleteListener {task ->if (task. issuccess) {task.result ?。让{registerTokenForChat (it)}} else {记录器。e(LOG_TAG, "检索FCM令牌失败")}}}private fun registerTokenForChat(token: String) {val pushNotificationsProvider = Chat.INSTANCE.providers()?if (pushNotificationsProvider == null) {记录器。e(LOG_TAG, "聊天未初始化,无法注册令牌")返回}pushNotificationsProvider.registerPushToken (token,对象:Zendesk亚博Callback() {重载onSuccess(result: Void?) {记录器。d(LOG_TAG, "Chat Push Enabled: %s",令牌)}重载onError(error: ErrorResponse?) {记录器。e(LOG_TAG, "Chat Error Enable Push\nReason: ${Error ?.responseBody}")}}}}}

步骤3 -在应用程序中创建Firebase代理服务

这是一个允许注册两个服务的helper类亚博ZendeskSDKFirebaseMessagingServiceChatSDKFirebaseMessagingService在你的应用中,这样每个SDK都能够接收推送通知。

FirebaseMessagingProxyService

             
进口android.app.Service进口com.google.firebase.messaging.FirebaseMessagingService进口com.google.firebase.messaging.RemoteMessage进口java.lang.reflect.FieldFirebaseMessagingProxyService: FirebaseMessagingService() {private val messagingServices: List by lazy {自然(亚博ZendeskSDKFirebaseMessagingService (),ChatSDKFirebaseMessagingService ()).onEach {it.injectContext(this)}}重载onNewToken(token: String) {super.onNewToken(令牌)messagingServices。forEach{它。onNewToken(token) }}重载onmessagerreceived (remoteMessage: remoteMessage) {super.onMessageReceived (remoteMessage)messagingServices。forEach{它。onMessageReceived(remoteMessage) }}重载onDeletedMessages() {super.onDeletedMessages ()messagingServices。forEach{它。onDeletedMessages() }}重载onMessageSent(消息:字符串){super.onMessageSent(消息)messagingServices。forEach{它。onMessageSent(message) }}重载onSendError(message: String, e: Exception) {超级。onSendError(消息,e)messagingServices。forEach{它。onSendError(message, e)}}}private fun  T. injectcontext (context: T, func: T () -> Unit = {}) {setField(“mBase上下文)函数()}私人娱乐类<*>。findDeclaredField(name: String): Field?{var: Class<*>?=这{做尝试{返回clazz ? .getDeclaredField(名称)} catch (_: Throwable) {}.superclass} while (null)返回null}私人娱乐任何。setField(name: String, value: Any): Boolean =javaClass.findDeclaredField(名字)?。让{尝试{它。isAccessible = true它。集(这个值)真正的} catch (e: Throwable) {}} ?: false

步骤4 -在AndroidManifest.xml文件中注册Firebase代理服务

             
<应用程序><!——使用Firebase代理消息服务——><服务android:出口=android:名字=.pushnotification.FirebaseMessagingProxyService><意图过滤器><行动android:名字=com.google.firebase.MESSAGING_EVENT/>意图过滤器>服务>应用程序>

从版本1.x迁移。X到2

Zend亚博esk SDK版本2.x。x及以上版本已经升级,以便我们在集成SDK时为您的产品中包含的功能提供灵活性。添加了一些令人兴奋的新功能,这将使您能够更好地与客户互动。

由于上面提到的更新,使用2.0.0以下SDK的任何版本的任何集成都需要进行迁移。

SDK初始化从消息传递模块到亚博模块。看到初始化SDK了解更多详情。初始化代码段现在接受消息传递的工厂实现,错误将作为Throwable对象而不是亚博ZendeskError对象。

以下消息传递函数也被迁移到亚博

Messaging.initialize(…) 亚博Zendesk.initialize(…)
.showMessaging Messaging.instance () () 亚博Zendesk.instance.messaging.showMessaging(…)

自动迁移

您可能能够使用Android Studio建议自动将您的初始化代码片段迁移到最新版本。

消息传递功能已在最新版本中弃用,并将在Android的未来版本中删除。