allboatsrise / expo-marketingcloudsdk

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

iOS issues #35

Closed aljazkosirnik-specto closed 1 week ago

aljazkosirnik-specto commented 2 weeks ago

I am stuck with this issue, SF support doesn't seem to know also, so I am looking for help here if anyone will know.

Android works and all the devices and contacts get set inside Marketing Cloud, but on iOS no promises resolve, it fails on the first function call.

Versions:

        "@allboatsrise/expo-marketingcloudsdk": "^50.2.0",
        "expo": "~50.0.17",
        "expo-notifications": "~0.27.7",

App config:

               // .........
        [
            '@allboatsrise/expo-marketingcloudsdk',
            {
                appId: envData.marketingcloudsdk.appId,
                accessToken: envData.marketingcloudsdk.accessToken,
                serverUrl: envData.marketingcloudsdk.serverUrl,
                mid: envData.marketingcloudsdk.mid,
                inboxEnabled: true,
                applicationControlsBadging: true,
                markNotificationReadOnInboxNotificationOpen: true,
                delayRegistrationUntilContactKeyIsSet: true,
            } as MarketingCloudSdkPluginProps,
        ],
        'expo-notifications',
               // .........

How I am testing it:

const [isDone, setIsDone] = useState(false);
    const [logs, setLogs] = useState<string[]>([]);

    useEffect(() => {
        let cleanup = () => {};

        (async () => {
            let result = await Notifications.getPermissionsAsync();
            if (!result.granted && result.canAskAgain) {
                result = await Notifications.requestPermissionsAsync({
                    ios: {
                        allowAlert: true,
                        allowBadge: true,
                        allowSound: true,
                    },
                });
            }

            if (!result.granted) {
                return;
            }

            const token = await Notifications.getDevicePushTokenAsync();

            // let Marketing Cloud SDK the value of current push token
            await MarketingCloud.setSystemToken(token.data);
            setIsDone(true);

            // In rare situations a push token may be changed by the push notification service while the app is running.
            const subscription = Notifications.addPushTokenListener((newToken) => {
                MarketingCloud.setSystemToken(newToken.data);
            });
            cleanup = () => subscription.remove();
        })();

        return () => cleanup();
    }, []);

    useEffect(() => {
        const logSubscription = addLogListener((logEvent: LogEventPayload) => {
            setLogs((prevLogs) => [...prevLogs, `Log event: ${logEvent.message}`]);
        });

        const inboxSubscription = addInboxResponseListener((inboxEvent: InboxResponsePayload) => {
            setLogs((prevLogs) => [...prevLogs, `Inbox event: ${inboxEvent.messages}`]);
        });

        const registrationSubscription = addRegistrationResponseSucceededListener(
            (registrationEvent: RegistrationResponseSucceededPayload) => {
                setLogs((prevLogs) => [...prevLogs, `Registration event: ${registrationEvent}`]);
            },
        );

        return () => {
            logSubscription.remove();
            inboxSubscription.remove();
            registrationSubscription.remove();
        };
    }, []);

Logs:

 LOG  Log event: {"category": "sfmcsdk", "level": 0, "message": "The module is not operational yet. Status: failed. This task will be queued.", "subsystem": "SFMCSdk"}
 LOG  Log event: {"category": "sfmcsdk", "level": 0, "message": "The module is not operational yet. Status: failed. This task will be queued.", "subsystem": "SFMCSdk"}
 LOG  Log event: {"category": "sfmcsdk", "level": 0, "message": "The module is not operational yet. Status: failed. This task will be queued.", "subsystem": "SFMCSdk"}

So it never goes over setSystemToken, the push token is valid, the promise never finishes. There is also no error when wrapping with try catch.

What I have also tried:

  1. Adding ContactKey before setStystemToken():
                await MarketingCloud.setContactKey(contactId);
                await MarketingCloud.setSystemToken(notificationToken);
                await MarketingCloud.enablePush();
  2. Removing additional stuff from app.config, like mid, inboxEnabled, applicationControlsBadging,..

Does anyone know where the issue might be? Why would the SDK fail on iOS, while Android works fine?

andrejpavlovic commented 2 weeks ago

Try setting: debug: true and analyticsEnabled: true.

If you don't see any new error messages, try building locally and see what shows up in xcode logs

mspallek-valantic commented 2 weeks ago

Hello!

I've been having exactly the same problem since updating to expo 50. All module functions (promises) are pending and neither fulfilled nor rejected. The SFMCSDK seems completely unresponsive.

As suggested, I've set debug: true and analyticsEnabled: true. However, I don't see any errors or anomalies in the logs.

Any ideas?

working:

"dependencies": {
    "@allboatsrise/expo-marketingcloudsdk": "^49.0.1",
    "expo": "~49.0.21",
    …
}    

not working:

"dependencies": {
    "@allboatsrise/expo-marketingcloudsdk": "^50.2.0",
    "expo": "^50.0.17",
    …
}    
andrejpavlovic commented 2 weeks ago

As suggested, I've set debug: true and analyticsEnabled: true. However, I don't see any errors or anomalies in the logs. You're not seeing any issue in xcode logs?

What appears in the logs after something like MarketingCloud.setSystemToken is called?

mspallek-valantic commented 2 weeks ago

What appears in the logs after something like MarketingCloud.setSystemToken is called?

Thank you for your quick reply! Unfortunately nothing at all.

But I noticed that not all functions are "unresponsive". That's the result of await MarketingCloud.getSdkState()

{
  "modules" : {
    "cdp" : {
      "compatibility" : "2.0.4 - 2.9.9",
      "name" : "cdp",
      "pendingOperations" : "undefined",
      "status" : "inactive",
      "version" : "unavailable"
    },
    "push" : {
      "compatibility" : "8.1.2 - 8.9.9",
      "name" : "push",
      "pendingOperations" : "undefined",
      "status" : "failed",
      "version" : "unavailable"
    }
  },
  "version" : "1.1.2"
}
andrejpavlovic commented 2 weeks ago

Seems like push module failed to load, which is basically the main module used by this integration. You'll have to take a closer look at the logs and/or paste them here.

mspallek-valantic commented 2 weeks ago

No idea why this is only showing up when running the development build in the Simulator, but anyway, finally got something:

Failed to initialize module SFMCSdkPushModule due to module version incompatibility. Provided version: 8.1.1, supported versions: >= 8.1.2 <= 8.9.9

edit: I just noticed that you bumped the MarketingCloudSDK version a few hours ago. I'm checking to see if it's working now…

edit2: @andrejpavlovic Yes, that was it! It's working again, thank you!

aljazkosirnik-specto commented 1 week ago

I can also confirm that the new v50.2.1 fixed the issue. Thank you!