Skip to main content

How to get started

warning

The majority of examples in this guide are splitted between two available development frameworks - UIKit and SwiftUI. Before the start of development process decide on using one of them and strictly follow the guides for the chosen framework where it's specified.

Installation

UIKit

InAppStory versionBuild versioniOS version
1.29.343120>= 11.0

SwfitUI

InAppStory versionBuild versioniOS version
1.29.34320>= 13.0

Version of the library can be obtained from the parameter InAppStory.buildInfo

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. Follow instructions on their website for seamless installation. To integrate InAppStory into your Xcode project using CocoaPods, specify it in your Podfile:

# UIKit
use_frameworks!
pod 'InAppStory', :git => 'https://github.com/inappstory/ios-ias-sdk.git', :tag => '1.29.2'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate InAppStory into your Xcode project using Carthage, specify it in your Cartfile:

# UIKit
github "inappstory/ios-ias-sdk" ~> 1.29.2

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but InAppStory does support its use on supported platforms.

Once you have your Swift package set up, adding InAppStory as a dependency is as easy as adding it to the dependencies value of your Package.swift.

//UIKit
dependencies: [
.package(url: "https://github.com/inappstory/IAS-iOS-SPM.git", .exact("1.29.2"))
]

XCode SPM installation

Alternatively, you can add an InAppStory via XCode:

  1. First click on the project;
  2. Select "Add Package Dependencies...";
  3. In the "Enter Package URL" field, specify the URL of this repository;
  4. Select package ias-ios-spm;
  5. Set "Dependecy rule" to "Exact Version" and specify the version required for installation;
  6. Click the "Add Package" button and wait for the installation to take place.

Manual installation

Download InAppStorySDK.xcframework from the repository. Connect in the project settings on the General tab.

Library import

Objective-C

#import <InAppStorySDK/InAppStorySDK.h>

Swift (UIKit)

import InAppStorySDK

SwiftUI

import InAppStorySDK_SwiftUI

Basic initialization

For a quick start and easy integration of InAppStorySDK, you need to:

  1. Initialize the library with settings;
  2. Create an instance of the list of stories on the screen;
  3. Process actions received from the library;

Library initialization

To initialize the library you need to get the integration key in the console - api-key. Next - install the library into the project in a convenient way for you. Installation.

It is better to initialize the library in the application at startup, for example in AppDelegate.

import UIKit
import InAppStorySDK

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
InAppStory.shared.initWith(serviceKey: <api-key>, settings: Settings(userID: <userID>, tags: <tags array>))
return true
}
}

In AppDelegate you can immediately configure Appearance and some library display options. An example with a few of the parameters is shown below. All parameters and properties can be viewed here and here.

extension AppDelegate {
func setupAppearance() {
// the parameter is responsible for logging to the XCode console
InAppStory.shared.isLoggingEnabled = true
// the parameter is responsible for displaying the shading under cell headers
InAppStory.shared.cellGradientEnabled = true
// the parameter is responsible for the color of the cell gradient of the unread story.
InAppStory.shared.cellBorderColor = UIColor.blue
// the parameter is responsible for displaying the bottom panel in the story card (likes, favorites and share)
// additionally should be configured in the console
InAppStory.shared.panelSettings = PanelSettings(like: true, favorites: true, share: true)
// the parameter is responsible for animation of the reader display when you tap on a story cell
InAppStory.shared.presentationStyle = .zoom
}
}

If UserID or tags are not known at the time of application initialization, they can be set later, before creating StoryView(UIKit) or StoryListView(SwiftUI). In this case, the initialization of InAppStory will look like this:

import UIKit
import InAppStorySDK

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
InAppStory.shared.initWith(serviceKey: <api-key>)
return true
}
}

Creating and launching a list of stories

To add a list to the screen, you need to create an instance of StoryView (UIKit) or StoryListView (SwiftUI) and run the internal logic.

import UIKit
import InAppStorySDK

class ViewController: UIViewController {
fileprivate var storyView: StoryView!

override func viewDidLoad() {
super.viewDidLoad()
createStoryView()
}
}

extension ViewController {
fileprivate func createStoryView() {
// get screen width
let screenWidth = UIScreen.main.bounds.width
// create an instance of the StoryView list
storyView = StoryView(frame: CGRect(origin: .zero, size: CGSize(width: screenWidth, height: 120)))

/* You can specify additional parameters
and settings for a particular list. before calling the `.create()` method
that starts the internal logic. */

// rewriting the settings, for the bottom panel with the story card set in InAppStory
storyView.panelSettings = PanelSettings(like: true, share: true)
// setting the scroll direction
storyView.direction = .horizontal()

// add the list to the screen
view.addSubview(storyView)
// start the internal logic
storyView.create()
}


}

All list parameters and settings can be viewed here.

(1.21.x) Handling list actions

If you need to handle list actions, such as clicking a link button or tracking a click on a favorite cell, you need to use InAppStoryDelegate. To do this, it must be specified in StoryView before calling the .create() method.

extension ViewController {
fileprivate func createStoryView() {
// get screen width
let screenWidth = UIScreen.main.bounds.width
// create an instance of the StoryView list
storyView = StoryView(frame: CGRect(origin: .zero, size: CGSize(width: screenWidth, height: 120)))
// specifying a delegate
storyView.storiesDelegate = self
// adding the list to the screen
view.addSubview(storyView)
// start the internal logic
storyView.create()
}
}

extension ViewController: InAppStoryDelegate {
func storiesDidUpdated(isContent: Bool, from storyType: InAppStorySDK.StoriesType) {
// processing of the list update
}

func storyReader(actionWith target: String, for type: InAppStorySDK.ActionType, from storyType: InAppStorySDK.StoriesType) {
// processing actions from StoryView, e.g. pressing a button with a link
}
}

(1.22.x) Handling list actions

If you need to handle actions in a list, such as clicking a link button or tracking a click on a favorite cell, you need to use closures. To do this, you must specify their implementation for InAppStory before calling the .create() method of StoryView

import UIKit
import InAppStorySDK

class ViewController: UIViewController {
fileprivate var storyView: StoryView!

override func viewDidLoad() {
super.viewDidLoad()
setupClosures()
createStoryView()
}
}

extension ViewController {
fileprivate func setupClosures() {
// setting the list update closure
InAppStory.shared.storiesDidUpdated = { isContent, storyType in
// handling of list update
}
// set closing actions in stories
InAppStory.shared.onActionWith = { target, actionType, storyType in
// handling actions from StoryView, e.g. pressing a button with a link
}
}

fileprivate func createStoryView() {
// get screen width
let screenWidth = UIScreen.main.bounds.width
// create an instance of the StoryView list
storyView = StoryView(frame: CGRect(origin: .zero, size: CGSize(width: screenWidth, height: 120)))
// add the list to the screen
view.addSubview(storyView)
// start the internal logic
storyView.create()
}
}

Closures can also be specified for a specific list. Such closures will overwrite the closures of InAppStory and will be prioritized, but will work only for the list to which they are specified. For this purpose, they must be specified in StoryView before calling the .create() method.

extension ViewController {
fileprivate func createStoryView() {
// get screen width
let screenWidth = UIScreen.main.bounds.width
// create an instance of StoryView list
storyView = StoryView(frame: CGRect(origin: .zero, size: CGSize(width: screenWidth, height: 120)))
// setting the list update closure
storyView.storiesDidUpdated = storiesDidUpdated(isContent:from::)
// set closing of actions in stories
storyView.onActionWith = onAction(actionWith:for:from::)
// adding the list to the screen
view.addSubview(storyView)
// start the internal logic
storyView.create()
}
}

extension ViewController {
func storiesDidUpdated(isContent: Bool, from storyType: InAppStorySDK.StoriesType) {
// processing of the list update
}

func onAction(actionWith target: String, for type: InAppStorySDK.ActionType, from storyType: InAppStorySDK.StoriesType) {
// processing actions from StoryView, e.g. pressing a button with a link
}
}