# Initial SDK Setup

This walkthrough shows how to add Storyly to your iOS application and show your first story in it.

You can also check out the demo on GitHub

Storyly Demo for Swift (opens new window)

Storyly Demo for Objective-C (opens new window)

Before you begin

This walkthrough contains sample instance information. However, if you want to work with your own content as well, please login into Storyly Dashboard (opens new window) and get your instance token.

The sample instance information for testing purposes;

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhY2NfaWQiOjc2MCwiYXBwX2lkIjo0MDUsImluc19pZCI6NDA0fQ.1AkqOy_lsiownTBNhVOUKc91uc9fDcAxfQZtpm3nj40

# Installation

WARNING

Storyly SDK targets iOS 9 or higher.

# CocoaPods

Storyly SDK is available through CocoaPods (opens new window). To integrate Storyly SDK into your Xcode project using CocoaPods, specify it in your Podfile:

use_frameworks!
pod 'Storyly'

Then run pod install.

DANGER

Please note that you need to use Storyly with use_frameworks! option in Podfile. If you need to add it without using use_frameworks! option, add following lines to your Podfile before updating Pods or check Manual Installation.

dynamic_frameworks = ['Storyly', 'SDWebImage']
pre_install do |installer|
  installer.pod_targets.each do |pod|
    if dynamic_frameworks.include?(pod.name)
      def pod.dynamic_framework?;
        true
      end
      def pod.build_type;
        Pod::BuildType.dynamic_framework
      end
    end
  end
end

WARNING

Please note that CocoaPods (opens new window) version should be 1.9+

# Carthage

Storyly SDK is available through Carthage (opens new window). To integrate Storyly SDK into your Xcode project using Carthage, specify it in your Cartfile:

binary "https://prod-storyly-media.s3.eu-west-1.amazonaws.com/storyly-sdk/Carthage/Storyly.json"
github "SDWebImage/SDWebImage" == 5.10.0

Then run carthage update --use-xcframeworks.

After, add the frameworks to your Xcode project: Go to targets and select your application. Click plus button from the Frameworks, Libraries, and Embedded Content section and add Storyly.xcframework and SDWebImage.xcframework. If you can't find, add from Add Other > Add files dialog. Frameworks will be located at Carthage/Build/.

WARNING

Please note that Carthage (opens new window) version should be 0.38+

# Swift Package Manager

Storyly SDK is available through SPM (opens new window). To integrate Storyly SDK into your Xcode project using SPM, add and enter package repository (opens new window)in the Swift Packages tab of your project.

# Manually

If you prefer not to use dependency managers, Storyly SDK releases are available through Storyly iOS SDK Releases (opens new window).

  • Download and unzip both Storyly.xcframework and SDWebImage.xcframework files.
  • Add the frameworks to your Xcode project: Use Finder to drag the both Storyly.xcframework and SDWebImage.xcframework folders into your Xcode project and drop it onto your project in the Project navigator window.
  • Follow the prompts to copy items into the destination and to create folder references.

# Add Storyly View

You need to import related modules to use Storyly:

    You can add StorylyView from Storyboard or Programmatically. Please follow the next sections.

    # Add Storyly View from Storyboard

    StorylyView extends UIView so that you can use inherited functionality as it is. So, you can add StorylyView to any of the app’s Storyboards and XIB Files.

    • Add a UIView in your Storyboard(or XIB File)
    • Define Custom Class as StorylyView in Identity Inspector.
    • Set height to 120 is suggested for better experience for default size

    # Add Storyly View Programmatically

    StorylyView extends UIView so that you can use inherited functionality as it is. So, you can initialize StorylyView using UIView’s constructors.

      WARNING

      Please note that if you use Auto Layout Constraints, you need to set translatesAutoresizingMaskIntoConstraints=false

      # Initialize StorylyView

      You are one step away from enjoying Storyly. You just need to init StorylyView.

        TIP

        Please do not forget to use your own token. You can get your token from the Storyly Dashboard -> Settings -> App Settings (opens new window)

        Just hit the run. Now, you should be able to enjoy Storyly 🎉!

        WARNING

        If you can't see Storyly in your application, please check that your token is correct. For more details please check console logs.

        # Set up Delegate

        This walkthrough shows you how to handle Storyly events in your app. Storyly events provide insight on what is happening on a Storyly instance such as loading states, user redirections, user interaction.

        Before you begin

        You need to have the working Storyly integration as described in Initial SDK Setup


        StorylyView notifies application when an event occurs. You can register the listener using the following code example and then override its functions to learn about specific events, which will be explained in the next sections.

          # StorylyLoaded Event

          This event will let you know that Storyly has completed its data operations, and the story group list has just been shown to the user. In addition to list of story groups, data source of the these groups is provided. In order to notified about this event, use the following example:

            # StorylyLoadFailed Event

            This event will let you know that Storyly has completed its network operations and had a problem while fetching your stories. In this case, users will see four empty story group icons, which we call skeleton view. In order to notified about this event, use the following example:

              # Show/Hide Storyly

              This guide shows use cases for showing or hiding Storyly bar in your app. To increase user experience when there are no stories available or stories are not loading using Storyly event handling.

              You can also check out the demo on GitHub

              Storyly Demo for Swift (opens new window)

              Storyly Demo for Objective-C (opens new window)

              # Show Storyly

              show-storyly-diagram

              Use case for showing storyly if StorylyView is loaded and stories are available.

              Add StorylyView to a UIViewController with parameter isHidden as true. Initialize StorylyView with token from dashboard.

              For not to show already visible StorylyView bar, check if initially load and storyGroupList size. Set StorylyView parameter isHidden to false.

              Event handling

              storylyLoaded event triggers first for available cached stories and second for request response with current stories. Detailed information about Event Handling

                # Hide Storyly

                show-storyly-diagram

                Use case for hiding storyly if StorylyView is not loaded and stories are not available.

                For not to show already visible StorylyView bar, check if initially loaded and storyGroupList size. Set StorylyView property isHidden to false.

                Loading cached stories triggers storylyLoaded event before storylyLoadFailed event. Check for if cache loaded and storyGroupList size. If cache is not loaded set StorylyView parameter isHidden to true.

                Event handling

                storylyLoaded event triggers first for available cached stories and later for up to date stories. storylyLoaded for cached stories will trigger before storylyLoadFailed.

                  # Test Mode

                  Before you begin

                  You need to have the working Storyly integration as described in Initial SDK Setup

                  This guide shows how to show test groups created in Storyly Dashboard to the specific devices. The default value of storylyTestMode is false, you need to explicitly define to set test devices.

                  <Storyly
                    style={{ width: '100%', height: 120 }}
                    ref={ref => { this.storyly = ref }}
                    storylyId=STORYLY_INSTANCE_TOKEN/>
                    storylyTestMode={true}