1

I'm facing an issue

I'm trying to integrate the Salesforce SDK into flutter and create a flutter plugin, so far everything is ok, only on android when the app is closed, I don't receive any notification, since communication between Flutter and native codes are via MethodChannel and binaryMessenger. So there is no OnCreate method in which I config the sdk ( It was mentioned in order to receive notification on background, it's a requirements).

Even I created a CustomFirebaseMessagingService to receive the push messages there, the messages are received there but when the app is terminated I don't get any notification(it's related to the SDK configuration which might be terminated). If I config and initialize the SDK on this onMessageReceived, I get the notifications but the context is differ from the flutter app's context.

class CustomMessagingService : FirebaseMessagingService() {

override fun onMessageReceived(message: RemoteMessage) {

    if (PushMessageManager.isMarketingCloudPush(message)) {
        SFMCSdk.requestSdk { sdk ->
            sdk.mp {
                it.pushMessageManager.handleMessage(message)
            }
        }
    }
}

override fun onNewToken(token: String) {

    SFMCSdk.requestSdk { sdk ->
        sdk.mp {
            it.pushMessageManager.setPushToken(token)
        }
    }
}

Any Idea how to resolve this issue ?

1 Answer 1

0

In your application's Application#onCreate() you must initialize the SDK. Without that, this will never work.

requestSdk is an asynchronous callback that is only executed after the SDK has finished initializing. If the application is killed and you receive a push notification, the application is launched and you should be initializing the SDK.

2
  • Thanks for your explanation, the problem here is flutter is not seemingly associated with native side via an activity, there exist an MainActivity which extends FlutterActivity and putting the initialization inside onCreate doesn't work, And on the other hand while creating a Flutter plugin to include the SFMC, there exist only an onAttachedToEngine method. I'm trying to implement this in Flutter for the first time, would appreciate if you have any idea about the issue , thanks . Aug 4, 2022 at 17:57
  • You need the application class, not an activity.
    – Bill Mote
    Aug 5, 2022 at 11:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .