Netvent/storyly-sdk

Resolving Failures in Story Deep Links Due to Unloaded SDK

Closed this issue · 1 comments

Environment Details

Storyly SDK Version: 2.10.1
iOS SDK Version: 17.2
Device Model: N/A
Device OS Version: N/A
Additional Info: N/A

Issue Summary

When initiating the app via a story deep link, calling StorylyView.openStory(payload:) before the SDK is fully loaded results in a failure, displaying an error: Storyly cannot be played due to empty data. Currently, there is no direct method to determine when the Storyly SDK is fully operational, leading to challenges in handling such failures effectively.

Detailed Description

The StorylyDelegate.storylyLoaded(:storyGroupList:dataSource:) callback is unreliable for this purpose as it can be triggered multiple times. The workaround involves asynchronously retrying the StorylyView.openStory(payload:) method with a delay, as shown in the following Swift code snippet:

public func openStory(_ url: URL) {
    var attemptCount = 0
    Timer.publish(every: 1.0, on: .main, in: .common)
        .autoconnect()
        .sink { [weak self] _ in
            guard let self = self else { return }
            if self.storylyView.openStory(payload: url) {
                cancellables.removeAll()
            } else {
                attemptCount += 1
                if attemptCount >= 5 {
                    cancellables.removeAll()
                }
            }
        }
        .store(in: &cancellables)
}

Expected Behavior

There should be a mechanism to asynchronously wait for the Storyly SDK to fully load before calling StorylyView.openStory(payload:).

Current Behavior

Currently, there is no direct way to ascertain when the Storyly SDK is fully loaded. The fallback method involves setting up retries with a delay, which is not ideal.

Steps to Reproduce

  1. Set Network Link Conditioner to Very Bad Network (optional but aids in reproducing the issue).
  2. Cold start the app by opening a story deep link.

Here are sample logs from when I reproduced this issue:
logs

Is there any better way to handle this case? Thanks!

Hi @bkunat,

Suggested Solutions:
To resolve this issue, consider the following solutions:
1.Call openStory before Initialization:
-Ensure that the openStory function is called before the initialization phase of the StorylyView.
2. Make openStory calls in storylyLoaded Event:

  • Utilize the storylyLoaded event to trigger your openStory calls.
  • storylyLoaded event is fired when the Storyly has updated its data.
  • storylyLoaded callback which can be triggered multiple times does not have any affect on openStory.

Thanks