Migration from Old to New SDK (iOS & Android) - Native

Migration from Old to New SDK (iOS & Android) - Native

FOR IOS:


1.  Replace current pods with

pod 'Dengage', '~> 5.1.1.1'

Replace

        setupDengage(with: launchOptions)

With

        setupDengage(with: launchOptions, application: application)


2. func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

        var token = "";

        if #available(iOS 13.0, *){

            

            token = deviceToken.map { String(format: "%02x", $0) }.joined()

        }

        else{

            let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }

            token = tokenParts.joined()

        }

        

Replace 

        sendToken(token)

With

        Dengage.register(deviceToken: deviceToken)

 

    }


3. Replace

 private func setupDengage(with launchOptions:[UIApplication.LaunchOptionsKey: Any]?){

        Dengage.setLogStatus(isVisible: true)

        Dengage.setIntegrationKey(key: Constans.DengageIntegrationKey)

        Dengage.initWithLaunchOptions(withLaunchOptions: launchOptions, badgeCountReset: true)

        Dengage.setUserPermission(permission: (true))

        Dengage.promptForPushNotifications()

    }

With

private func setupDengage(with launchOptions:[UIApplication.LaunchOptionsKey: Any]? , application : UIApplication){

        Dengage.setLogStatus(isVisible: true)

        Dengage.setIntegrationKey(key: Constans.DengageIntegrationKey)

        Dengage.initWithLaunchOptions(application: application, withLaunchOptions: launchOptions ?? [:])

 

        UNUserNotificationCenter.current().delegate = self

        Dengage.promptForPushNotifications()

        Dengage.setLogStatus(isVisible: true)

    }



ADD 3 New Functions


func application(_ application: UIApplication,

                     didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {

        Dengage.didReceive(with: userInfo)

    }

    

    func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {

        print("Failed to register for notifications: \(error.localizedDescription)")

    }

    

 

 

    func userNotificationCenter(_ center: UNUserNotificationCenter,

                                didReceive response: UNNotificationResponse,

                                withCompletionHandler completionHandler: @escaping () -> Void){

        Dengage.didReceivePush(center, response, withCompletionHandler: completionHandler)

    }

 

    final func userNotificationCenter(_ center: UNUserNotificationCenter,

                                      willPresent notification: UNNotification,

                                      withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {

        if #available(iOS 14.0, *) {

            completionHandler([.banner, .sound, .badge])

        } else {

            // Fallback on earlier versions

            completionHandler([.alert, .sound, .badge])

 

        }

    }



FOR ANDROID :


'com.github.dengage-tech:dengage-android-sdk:x.y.z



Change dependency to 5.6.1 for non geofence
5.6.2 without huawei and geofence
5.6.3 with geofence with huawei
5.6.4 with geofence without huwaei


REPLACE Service in manifest :

com.dengage.sdk.FcmMessagingService
com.dengage.sdk.HmsMessagingService




To

com.dengage.sdk.push.FcmMessagingService
com.dengage.sdk.push.HmsMessagingService


  If they have registered any receiver for carousel then

Change their carousel structure to this

import com.dengage.sdk.domain.push.model.CarouselItem

import com.dengage.sdk.domain.push.model.Message

import com.dengage.sdk.push.NotificationReceiver


class PushNotificationReceiver : NotificationReceiver() {


   override fun onCarouselRender(

       context: Context,

       intent: Intent,

       message: Message,

       leftCarouselItem: CarouselItem,

       currentCarouselItem: CarouselItem,

       rightCarouselItem: CarouselItem

   ) {

       super.onCarouselRender(

           context,

           intent,

           message,

           leftCarouselItem,

           currentCarouselItem,

           rightCarouselItem

       )


       val itemTitle = currentCarouselItem.title

       val itemDesc = currentCarouselItem.description


       // set intents (right button, left button, item click)

       val itemIntent = getItemClickIntent(intent.extras, context.packageName)

       val leftIntent = getLeftItemIntent(intent.extras, context.packageName)

       val rightIntent = getRightItemIntent(intent.extras, context.packageName)

       val deleteIntent = getDeleteIntent(intent.extras, context.packageName)

       val contentIntent = getContentIntent(intent.extras, context.packageName)


       val carouseItemIntent = getPendingIntent(context, 0, itemIntent)

       val carouselLeftIntent = getPendingIntent(context, 1, leftIntent)

       val carouselRightIntent = getPendingIntent(context, 2, rightIntent)

       val deletePendingIntent = getPendingIntent(context, 4, deleteIntent)

       val contentPendingIntent = getPendingIntent(context, 5, contentIntent)


       // set views for the layout

       val collapsedView = RemoteViews(

           context.packageName,

           R.layout.den_carousel_collapsed

       )

       collapsedView.setTextViewText(R.id.den_carousel_title, message.title)

       collapsedView.setTextViewText(R.id.den_carousel_message, message.message)


       val carouselView = RemoteViews(

           context.packageName,

           R.layout.den_carousel_portrait

       )

       carouselView.setTextViewText(R.id.den_carousel_title, message.title)

       carouselView.setTextViewText(R.id.den_carousel_message, message.message)

       carouselView.setTextViewText(R.id.den_carousel_item_title, itemTitle)

       carouselView.setTextViewText(R.id.den_carousel_item_description, itemDesc)


       carouselView.setOnClickPendingIntent(R.id.den_carousel_left_arrow, carouselLeftIntent)

       carouselView.setOnClickPendingIntent(

           R.id.den_carousel_portrait_current_image,

           carouseItemIntent

       )

       carouselView.setOnClickPendingIntent(R.id.den_carousel_item_title, carouseItemIntent)

       carouselView.setOnClickPendingIntent(R.id.den_carousel_item_description, carouseItemIntent)

       carouselView.setOnClickPendingIntent(R.id.den_carousel_right_arrow, carouselRightIntent)


       val channelId = createNotificationChannel(context, message)


       loadCarouselImageToView(

           carouselView = carouselView,

           imageViewId = R.id.den_carousel_portrait_left_image,

           carouselItem = leftCarouselItem,

           onComplete = {

               // you can call notificationManager.notify for devices that could not show carousel image contents

           }

       )


       loadCarouselImageToView(

           carouselView = carouselView,

           imageViewId = R.id.den_carousel_portrait_current_image,

           carouselItem = currentCarouselItem,

           onComplete = {

               // you can call notificationManager.notify for devices that could not show carousel image contents

           }

       )


       loadCarouselImageToView(

           carouselView = carouselView,

           imageViewId = R.id.den_carousel_portrait_right_image,

           carouselItem = rightCarouselItem,

           onComplete = {

               // you can call notificationManager.notify for devices that could not show carousel image contents

           }

       )


       val notification = NotificationCompat.Builder(context, channelId)

           .setSmallIcon(R.mipmap.ic_launcher)

           .setCustomContentView(collapsedView)

           .setCustomBigContentView(carouselView)

           .setContentIntent(contentPendingIntent)

           .setDeleteIntent(deletePendingIntent)

           .build()


       // show message again silently with next, previous and current item.

       notification.flags = Notification.FLAG_AUTO_CANCEL or Notification.FLAG_ONLY_ALERT_ONCE


       // show message

       val notificationManager = NotificationManagerCompat.from(context)

       notificationManager.notify(

           message.messageSource,

           message.messageId,

           notification

       )

   }




    • Related Articles

    • Migration from Old to New SDK (React)

      React Native Version: 0.3.1 without geofence with Huawei 0.3.2 without geofence with Huawei 0.3.3 with geofence with Huawei 0.3.4 with geofence without Huawei FOR IOS: 1.  Replace current pods with Without geofence:  pod 'Dengage', :git => ...
    • Where can I see latest SDK version?

      The following link provides where the documentation is available for the SDK version. You can use the following links relevant to the technologies to see the required SDK version. IOS SDK Android SDK Huawei SDK React Native Cordova Flutter
    • Migration from Old to New SDK (Flutter)

      Flutter versions 0.3.3 without geofence with huawei 0.3.4 without geofence without huawei 0.3.5 with geofence with huawei 0.3.6 with geofence without huawei FOR IOS: 1.  Replace current pods with  pod 'Dengage', :git => ...
    • Experience Module Android SDK Integration

      Android SDK¶ Dengage Android SDK for sending visitor behavior and rendering product recommendations. Supports Android 4.4 and higher devices. Important warning ProductView, Basket Add/Remove, View Basket, Purchase and Click events must match ...
    • Experience Module iOS SDK Integration

      iOS SDK¶ Dengage iOS SDK for sending visitor behavior and rendering product recommendations. Important warning ProductView, Basket Add/Remove, View Basket, Purchase and Click events must match productId. Introduction¶ This tutorial provides a very ...