allboatsrise / expo-marketingcloudsdk

Expo module for Salesforce Marketing Cloud SDK
MIT License
12 stars 12 forks source link

iOS: Module is not initialized. You need to initialize before using. Current status: failed #8

Closed MarchewkaMatthew closed 1 year ago

MarchewkaMatthew commented 1 year ago

Hi @andrejpavlovic !

Thank you for maintaining this module. Last time we talked in April, you helped me to set up the notifications for both Android and iOS. We had some problems with the Android notifications so we were focused on that. Unfortunately, yesterday we realized that the iOS notifications are no longer working for us.

It seems that the Salesforce module is not initialized in our app. Should we do anything else than:

    const devicePushToken = await Notifications.getDevicePushTokenAsync();
    await MarketingCloud.enablePush();
    await MarketingCloud.setSystemToken(devicePushToken.data);

Of course before this code we take care about providing the permissions for the notifications.

Expected Behavior

The module is initialized on iOS, so we can register the device in Salesforce and set and fetch data like contactKey or attributes.

Actual Behavior

After enabling the log listener I receive this message to the console: {"category": "interface", "level": 0, "message": "Module is not initialized. You need to initialize before using. Current status: failed", "subsystem": "SFMCSdk"} Worth to mention that the same code works for Android without the problem. Are you familiar with this error? Do you know what may cause this issue only for iOS devices? Should we initialize the module from our code, or it should be initialized automatically? Any help would be appreciated.

Specifications

package.json:

    "@allboatsrise/expo-marketingcloudsdk": "48.0.0",
    "@expo/config-plugins": "~6.0.0",
    "expo": "^48.0.6",
    "expo-notifications": "~0.18.1",

app.config.ts:

      [
        "@allboatsrise/expo-marketingcloudsdk",
        {
          appId: process.env.SALESFORCE_APP_ID ?? easTestEnv.SALESFORCE_APP_ID,
          accessToken: process.env.SALESFORCE_ACCESS_TOKEN ?? easTestEnv.SALESFORCE_ACCESS_TOKEN,
          serverUrl: process.env.SALESFORCE_SERVER_URL ?? easTestEnv.SALESFORCE_SERVER_URL,
          mid: "<MID>",
          senderId: "<SENDER_ID>",
          analyticsEnabled: false,
          applicationControlsBadging: false,
          inboxEnabled: true,
          locationEnabled: false,
          iconFile: path.join(__dirname, "assets", "images", "notification-icon.png"),
        } as MarketingCloudSdkPluginProps,
      ],
      "expo-notifications",

(removed the value from mid and senderId) For now, pasting only related packages, if needed I can provide more.

Thank you in advance for your help!

eridr commented 1 year ago

Yes, it seems like the libraries MarketingCloudSDK is outdated.

Current MarketingCloudSDK:

s.dependency 'MarketingCloudSDK', '8.0.10'
Failed to initialize module MarketingCloudSDK.PushModule due to module version incompatibility. Provided version: 8.0.10, supported versions: >= 8.0.12 <= 8.9.9
eridr commented 1 year ago

Perhaps version: 8.0.13 could be used?

https://salesforce-marketingcloud.github.io/MarketingCloudSDK-iOS/

MarchewkaMatthew commented 1 year ago

I made a fork and updated the version to 8.0.13 and it indeed helped. I still need to figure out a fix for one problem. getAttributes returns null instead of empty object (so maybe I need to adjust the lib a little bit more), when I finish my fixes I will publish the PR to this repo.

eridr commented 1 year ago

@MarchewkaMatthew We hade issues with init the SDK on 8.0.13 but 8.0.12 seems to work.

andrejpavlovic commented 1 year ago

Bumped MarkingCloudSDKs to latest version (iOS and Android) in 48.0.2 https://github.com/allboatsrise/expo-marketingcloudsdk/pull/13

andrejpavlovic commented 1 year ago

Updated typescript types to match nullable values potentially returned on iOS in 48.0.3 https://github.com/allboatsrise/expo-marketingcloudsdk/pull/14