Skip to main content

Reference

InAppStory closures​

  • InAppStoryDelegate
  • StoryViewDelegateFlowLayout
  • GoodsDelegateFlowLayout.

delegate methods have been carried over as closures of the InAppStory class:

// InAppStoryDelegate closures

// called after the contents are updated for stories type
public var storiesDidUpdated: ((_ isContent: Bool, _ storyType: StoriesType) -> Void)? = nil
// called by action in Reader
public var onActionWith: ((_ target: String, _ type: ActionType, _ storyType: StoriesType?) -> Void)? = nil

// called before the reader will show (optional)
public var storyReaderWillShow: ((_ storyType: StoriesType) -> Void)? = nil
// called after closing the story reader (optional)
public var storyReaderDidClose: ((_ storyType: StoriesType) -> Void)? = nil

//called when the favorite cell has been selected (optional)
public var favoriteCellDidSelect: (() -> Void)? = nil
// called after UGC editor cell is tapped in stories list
public var editorCellDidSelect: (() -> Void)? = nil

// get goods items from parent app with closure
public var getGoodsObject: ((_ skus: Array<String>, _ complete: @escaping GoodsComplete) -> Void)? = nil
// selected goods item in widget, with object sent in
public var goodItemSelected: ((_ item: GoodsObjectProtocol, _ storyType: StoriesType?) -> Void)? = nil

// StoryViewDelegateFlowLayout closures
// returns the cell size for the list
public var sizeForItem: (() -> CGSize)? = nil
// returns padding from the edges of the list for cells
public var insetForSection: (() -> UIEdgeInsets)? = nil
// the spacing between successive rows or columns of a section
public var minimumLineSpacingForSection: (() -> CGFloat)? = nil
// the spacing between successive items of a single row or column
public var minimumInteritemSpacingForSection: (() -> CGFloat)? = nil

// GoodsDelegateFlowLayout closures
// returns the cell size for the list
public var goodsSizeForItem: (() -> CGSize)? = nil
// returns padding from the edges of the list for cells
public var goodsInsetForSection: (() -> UIEdgeInsets)? = nil
// the spacing between successive rows or columns of a section
public var goodsMinimumLineSpacingForSection: (() -> CGFloat)? = nil

Due to the transfer of logic from delegates to closures, the StoryListView and StoryListUGCView list interfaces were updated. Closures were removed from the initialization methods. The closures were moved to variables that can be called from an instance of the class.

Code example

ContentView.swift - old​

struct ContentView: View
{
var body: some View {
VStack(alignment: .leading) {
StoryListView(feed: <String?>,
isFavorite: <Bool>,
panelSettings: <PanelSettings>?,
isEditorEnabled: <Bool>,
onUpdated: <((Bool) -> Void)?>,
onAction: <((String, ActionType) -> Void)?>,
onDismiss: <(() -> Void)?>,
favoritesSelect: <(() -> Void)?>,
getGoodsObjects: <((Array<String>, (Result<Array<GoodsObjectProtocol>, GoodsFailure>) -> Void) -> Void)?>,
selectGoodsItem: <((GoodsObjectProtocol) -> Void)?>,
refresh: <Binding<Bool>>)
Spacer()
}
}
}

ContentView.swift - new​

struct ContentView: View
{
var body: some View {
VStack(alignment: .leading) {
StoryListView(feed: <String?>,
isFavorite: <Bool>,
panelSettings: <PanelSettings>?,
isEditorEnabled: <Bool>,
refresh: <Binding<Bool>>)
.onUpdate { isContent, storyType in
// called when the list is updated
}
.willAppear({ storyType in
// called before reader's screen
})
.onDismiss({ storyType in
// called after reader screen is closed
})
.onAction { target, type, storyType in
// called if an action has occurred in the story
}
.favoriteDidSelect {
// is called when the favorite cell has been clicked
}
.editorDidSelect {
// called when the editor cell was clicked
}
.getGoodsObject { skus, complete in
// called to get the list of goods
}
.goodItemSelected { item, storyType in
// called when an item in a widget is selected
}
Spacer()
}
}
}

Protocols​

InAppStoryDelegate​

warning

InAppStoryDelegate is deprecated in versions 1.22.0 and above. It is necessary to use InAppStory closures.

  • storiesDidUpdated(isContent: <Bool>, from storyType: <StoriesType>, storyView: <StoryView>?) - called after the contents are updated for stories type <StoriesType>;
  • storyReader(actionWith target: <String>, for type: <ActionType>, from storyType: <StoriesType>, storyView: <StoryView>?) - called after a link is received from stories with the interaction type <ActionType> and <StoriesType>;
  • storyReaderWillShow(with storyType: <StoriesType>, storyView: <StoryView>?) - called before the reader will show (optional);
  • storyReaderDidClose(with storyType: <StoriesType>, storyView: <StoryView>?) - called after closing the story reader (optional);
  • favoriteCellDidSelect() - called when the favorite cell has been selected (optional);
  • getGoodsObject(with skus: <Array<String>>, complete: <GoodsComplete>) - get goods items from parent app with closure, <GoodsComplete>;
  • goodItemSelected(_ item: <Any>, with storyType: <StoriesType>, storyView: <StoryView>?) - selected goods item in widget, with object sent in getGoodsObject(...)

GoodsDelegateFlowLayout​

warning

GoodsDelegateFlowLayout is deprecated in versions 1.22.0 and above. It is necessary to use InAppStory closures.

Methods of delegate, like in UICollectionViewDelegateFlowLayout:

  • sizeForItemAt() -> <CGSize> - returns the cell size for the list;
  • insetForSection() -> <UIEdgeInsets> - returns padding from the edges of the list for cells;
  • minimumLineSpacingForSection() -> <CGFloat> - the spacing between successive rows or columns of a section;

StoryViewDelegateFlowLayout​

warning

StoryViewDelegateFlowLayout is deprecated in versions 1.22.0 and above. It is necessary to use InAppStory closures.

Methods of delegate, like in UICollectionViewDelegateFlowLayout:

  • sizeForItemAt() -> <CGSize> - returns the cell size for the list;
  • insetForSection() -> <UIEdgeInsets> - returns padding from the edges of the list for cells;
  • minimumLineSpacingForSection() -> <CGFloat> - the spacing between successive rows or columns of a section;
  • minimumInteritemSpacingForSection() -> <CGFloat> - the spacing between successive items of a single row or column;

PlaceholderProtocol​

  • isAnimate: <Bool> { get } - returns the state of the animation
  • start - start animation
  • stop - stop animation

InputPresenter​

Available since SDK 1.29.9 (4370) for custom input interfaces in IAM, banners, and games. Set InAppStory.shared.inputPresenter; its default nil keeps the standard SDK dialog. The SDK retains the presenter.

  • presentInput(request: InputRequest, from controller: UIViewController, completion: @escaping (InputResult) -> Bool) - shows your input interface. Submit or cancel through completion; true means accepted, false means invalid input or an already closed request. On acceptance, the SDK calls dismissInput; do not dismiss before submitting.
  • dismissInput(completion: @escaping () -> Void) - dismisses only this input interface and calls completion exactly once when finished, including when already closed.

All calls and completions must run on the main thread. See configuration and lifecycle.

DownloadPlaceholderProtocol​

  • func setProgress(progress: Double) - setting the progress value (0.0 - 1.0)

StoryCellProtocol​

  • reuseIdentifier: <String> { get } - returns cell reuse identifier;
  • nib: <UINib?> { get } - returns the nib of the cell's visual representation;
  • storyID: <String!> { get set } - cell's story id;
  • setTitle(_ text: <String>) - story title;
  • setImageURL(_ url: <URL>) - image url for cover;
  • setVideoURL(_ url: <URL>) - video url for animated cover;
  • setOpened(_ value: <Bool>) - set new state if story is opened;
  • setHighlight(_ value: <Bool>) - set new state if story cell if highlighted;
  • setBackgroundColor(_ color: <UIColor>) - background color of cell;
  • setTitleColor(_ color: <UIColor>) - title color of cell;
  • setSound(_ value: Bool) - does the story have sound;
  • setUGCPayload(_ payload: Dictionary<String, Any>) - payload transfer for UGC stories;

GoodsObjectProtocol​

  • sku: <String!> { get set } - product sku, more at GoodsObject;

GoodsCellProtocol​

  • reuseIdentifier: <String> { get } - returns cell reuse identifier;
  • nib: <UINib?> { get } - returns the nib of the cell's visual representation;
  • setGoodObject(_ object: <Any>!) - object that comes from getGoodsObject(...);

FavoriteCellProtocol​

  • reuseIdentifier: <String> { get } - returns cell reuse identifier;

  • nib: <UINib?> { get } - returns the nib of the cell's visual representation;

  • favoritesCount: Int { get set } - total count of stories in favorites;

  • setHighlight(_ value: <Bool>) - set new state if story cell if highlighted;

  • setImages(_ urls: <Array<URL?>>) - a list of addresses of the first four images stories in favorites;

  • setImagesColors(_ colors: <Array<UIColor?>>) - a list of background colors of the first four stories in favorites;

  • setBackgroundColor(_ color: <UIColor>) - main background color of a cell;

EditorCellProtocol​

  • reuseIdentifier: <String> { get } - returns cell reuse identifier;
  • nib: <UINib?> { get } - returns the nib of the cell's visual representation;

Closure​

GoodsComplete​

warning

InAppStoryDelegate is deprecated in versions 1.22.0 and above. It is necessary to use InAppStory closures.

Closure for contine getGoodsObject(...) method in InAppStoryDelegate - (Result<Array<Any>, GoodsFailure>) -> Void

Enum​

ListDirection​

Direction of scrolling stories list, individual for each list

  • horizontal(rows: Int) - horizontal scrolling with the number of lines, the default is 1;
  • vertical(colums: Int) - vertical scrolling with the number of columns, the default is 3;

ScrollStyle​

Story transition animation style in reader:

  • .flat - usual, one after another, like UIScrollView;
  • .cover - covered with next slide;
  • .depth - covered with next slide with previos slide alpha;
  • .cube - in the form of a 3D cube;

PresentationStyle​

Reader display animation style:

  • .crossDissolve - showing reader from transparency;
  • .modal - modal reader display;
  • .zoom - display reader from list's cell;

ClosePosition​

Position of the close button on the card in the reader:

Renamed from version 1.25.0

  • .left - to the left of the timers (renamed at 1.25.0);
  • .right - to the right of the timers (renamed at 1.25.0);
  • .bottomLeft - on the left under the timers (renamed at 1.25.0);
  • .bottomRight - on the right under the timers (renamed at 1.25.0);

Since version 1.25.0

  • .leading - leading by story card, at the timer level
  • .trailing - trailing by story card, at the timer level
  • .leadingBottom - leading by story card, under the timer level
  • .trailingBottom - trailing by story card, under the timer level

ActionType​

The action by which the link was obtained:

  • .button - push the button;
  • .swipe - swipe up slide;
  • .game - link from Game;
  • .deeplink - deeplink from cell.

StoriesType​

The action by which the link was obtained:

  • .list(feed: <String>?) - type for StoryView, feed - id stories list;
  • .single - type for single story reader;
  • .onboarding(feed: <String>) - type for onboarding story reader, feed - id stories list.

Quality​

Quality of cover images in cells

  • .medium;
  • .high.

GoodsFailure​

Failure that return in Result from getGoodsObject(...) closure

  • .refresh - show refresh button in the GoodsView;
  • .close - close GoodsView.

Objects​

InputRequest and InputResult​

Available since SDK 1.29.9 (4370). InputRequest is supplied by the SDK to InputPresenter; applications do not construct it directly.

Read-only propertyTypeMeaning
idStringInput request identifier.
typeInputRequest.InputType.text, .email, or .telephone.
titleString?Optional dialog title.
placeholderStringInput placeholder.
buttonTitleStringSubmit button title.
initialValueStringInitial text; empty for email and telephone requests.
characterLimitIntCharacter limit for text validation.
maxLinesIntVisible line limit for the standard text area's height; additional lines scroll. Email and telephone use one line. This is not a submitted line-count limit.

For IAM and banners, omitted content settings give title: nil, buttonTitle: "Submit", characterLimit: 255, and maxLines: 1. The default placeholder is "name@example.com" for email and "Your answer" otherwise. Negative character limits are clamped to 0, and text maxLines is at least 1. Initial text is truncated to the character limit. Game requests supply their own labels, use Int.max for the text character limit and 5 visible text lines, and start with an empty value.

isValid(_ value: String) -> Bool checks the requested input type and its validation rules. Text must be nonempty and within characterLimit; whitespace is not trimmed, and line count is not checked. Email uses the SDK's email validation without applying the text character limit. Telephone values use +<country code> <number>, for example +7 999 123 45 67, with a 1–4 digit country code and spaces allowed in the number. Known country codes use the first matching SDK phone mask's digit count; unknown codes accept 5–14 digits. Use this method before enabling submission.

InputResult has two cases: .submitted(String) and .cancelled. Pass one to the result closure from presentInput. With inputPresenter = nil (the default), the SDK handles this entire interaction through its standard dialog.

Settings​

Parameters​

  • userID - unique user identifier <String>;
  • sign - user id signature for security <String>;
  • tags - list of tags for content filtering <Array\<String>>;
  • placeholders - list of text placeholders for content personalization Dictionary<String, String>;
  • imagesPlaceholders - list of image placeholders for content personalization Dictionary<String, String>;
  • lang - sets the language used in widgets, notifications, game text elements <String>. The format must match the system format in order to correctly create a Locale object by identifier (en-EN | ar-SA);
warning

When setting a new Settings object in InAppStory, if the previous userID, sign and lang parameters are not equal to what they were before, a new session will be opened, which will result in updating feeds and closing all readers.

PanelSettings​

Parameters​

  • like - displaying the bottom bar with likes (should be enabled in the console) <Bool>;
  • favorites - displaying the bottom bar with favorites (should be enabled in the console) <Bool>;
  • share - displaying the bottom panel with sharing (should be enabled in the console) <Bool>;

TimersGradient​

In SDK 1.29.9 (4370), the default colors are transparent black and black with alpha 0.3; before 1.29.9, the end alpha was 0.1. The other initializer defaults are startPoint: CGPoint(x: 0.5, y: 1), endPoint: CGPoint(x: 0.5, y: 0), locations: [0, 1], and height: 200. See keeping the previous colors.

Parameters​

  • colors - array of gradient colors <Array<UIColor>>;
  • startPoint - start point of gradient <CGPoint>;
  • endPoint - end point of gradient <CGPoint>;
  • locations - smooth gradient location <Array<Double>;
  • height - the height of the gradient from the top edge of the story <Double>;

BottomPanelGradient​

This value type is publicly declared since SDK 1.29.9 (4370), but build 4370 provides no public setting that applies it to the reader: InAppStory.shared.bottomPanelGradient and its AppearanceAPI counterpart are internal. Fullscreen story rendering is not enabled for server content in this build.

The public initializer and mutable properties are colors: [UIColor] (default: black with alpha 0.3, then transparent black), startPoint: CGPoint (default: (0.5, 1)), endPoint: CGPoint (default: (0.5, 0)), locations: [Double] (default: [0, 1]), and height: Double (default: 200). Constructing this value alone does not change the UI.

WidgetStory​

Parameters​

  • id - unique identifier of story <String>;
  • title - story title <String>;
  • image - link to cover image <String>;
  • color - background color of the story in HEX format <String>;

GoodsObject​

Default product object that implements the protocol GoodsObjectProtocol

Parameters​

  • sku: <String!> - sku product;
  • title: <String?> - product title;
  • subtitle: <String?> - product description;
  • imageURL: <URL?> - link to the product image;
  • price: <String?> - current price of the product;
  • oldPrice: <String?> - old price of the product;

CustomGoodsView​

To create your own goods widget, you need to inherit from CustomGoodsView.

Parameters​

  • setSKUItems(_ items: Array<String>) - set SKUs of goods from InAppStory reader;
  • setReaderFrame(_ frame: CGRect) - set StoryReader frame;
  • final close() - needs call from superclass, for close widget;
  • final goodsItemClick(with sku: <String>) - send statistic in SDK;

EditorCellSettings​

To change the appearance of the UGC editor cell, use this object.

Parameters​

  • backgroundColor - background color of the cell <UIColor>
  • iconColor - tint color of the icon in the cell <UIColor>
  • iconImage - custom icon <UIImage>

VisibleStoryItem​

Parameters​

  • storyId - id of the shown story <Int>
  • index - index of the story in the list <Int>
  • title - title of the story <String?>
  • feed - the feed in which the story is located <String>
  • tags - list of tags of stories <Array<String>>
  • slidesCount - number of slides in the story <Int>
  • visiblePercents - area shown on the screen from the storis cell in percent <Double>