Customize click behaviors (iOS)

The SDK provides behavior delegate methods to customize click behaviors, including those for the video CTA button, product cards, and shopping CTA button.

Customize video overlay CTA button click behavior

  1. Set FireworkVideoCTADelegate delegate:

FireworkVideoSDK.ctaDelegate = <FireworkVideoCTADelegate delegate>

2. Implement handleCustomCTAClick(_:url:for:):

func handleCustomCTAClick(
    _ viewController: PlayerViewController,
    url: URL,
    for video: VideoDetails
) -> Bool {
    // Here, you could write codes to navigate to the host app page.
    // Please refer to "Navigate to the host app page" below for more details.

    // Return true to customize video overlay CTA button click behavior
    return true
}

Customize click behaviors for shopping

To customize click behaviors for shopping, you need to set FireworkVideoShoppingDelegate delegate first:

FireworkVideoSDK.shopping.delegate = <FireworkVideoShoppingDelegate delegate>

Customize product card click behavior

Implement fireworkShopping(_:didTapProductVariant:forVideo:):

func fireworkShopping(
    _ fireworkShopping: FireworkVideoShopping,
    didTapProductVariant item: SelectedProductVariant,
    forVideo video: VideoDetails
) -> Bool {
    // Here, you could write codes to navigate to the host app page.
    // Please refer to "Navigate to the host app page" below for more details.

    // Return true to customize product card click behavior
    return true
}

Customize shopping CTA click behavior

Implement fireworkShopping(_:productVariantCTASelected:fromVideo:ctaCompletionHandler:):

func fireworkShopping(
    _ fireworkShopping: FireworkVideoShopping,
    productVariantCTASelected item: SelectedProductVariant,
    fromVideo video: VideoDetails,
    ctaCompletionHandler: @escaping ShoppingCTAHandler
) {
    // Here, you could write codes to navigate to the host app page.
    // Please refer to "Navigate to the host app page" below for more details.

    // Calling completion closure with none refer to
    // host app will customize the click behavior
    ctaCompletionHandler(.none)
}

Implement fireworkShopping(_:didTapLinkButtonAt:fromVideo:withURL:):

func fireworkShopping(
        _ fireworkShopping: FireworkVideoShopping,
        didTapLinkButtonAt item: SelectedProductVariant,
        fromVideo video: VideoDetails,
        withURL itemURL: String
    ) -> Bool {
        // Here, you could write codes to navigate to the host app page.
        // Please refer to "Navigate to the host app page" below for more details.

        // Return true to customize product link button click behavior
        return true
}

Customize cart icon click behavior

  1. Set cartAction to custom:

FireworkVideoSDK.shopping.cartAction = .custom
  1. Implement fireworkShopping(_:didTapCartIconForVideo:):


func fireworkShopping(
    _ fireworkShopping: FireworkVideoShopping,
    didTapCartIconForVideo videoDetails: VideoDetails
) {
    // Here, you could write codes to navigate to the host app page.
    // Please refer to "Navigate to the host app page" below for more details.
}
  1. Set FireworkLiveStreamBehaviorDelegate delegate:

FireworkVideoSDK.liveStreamBehaviorDelegate = <FireworkLiveStreamBehaviorDelegate delegate>
  1. Implement fireworkLiveStream(_:didTapLinkInteraction:):

func fireworkLiveStream(
    _ liveStream: LiveStreamEventDetails,
    didTapLinkInteraction interaction: LiveStreamLinkInteraction
) -> Bool {
    // Here, you could write codes to navigate to the host app page.
    // Please refer to "Navigate to the host app page" below for more details.

    // Return true to customize livestream link interaction click behavior
    return true
}

We have three ways to navigate to the host app page when customizing click behaviors.

  1. Present the host app page over the SDK player.

  2. Use the host app navigation controller to push the host app page.

Present the host app page

As the following code snippets, we use "present" to navigate to the host app PDP page. The code snippets are:

func fireworkShopping(
    _ fireworkShopping: FireworkVideoShopping,
    didTapProductVariant item: SelectedProductVariant,
    forVideo video: VideoDetails
) -> Bool {
    // The following PDP view controller is a sample.
    // Please create your own PDP view controller.
    let pdpVC = UIViewController()
    // As we may have other flows in PDP(such as the checkout page),
    // we could embed the PDP controller with navigation controller.
    let nav = UINavigationController(rootViewController: pdpVC)
    nav.modalPresentationStyle = .fullScreen
    UIViewController.topPresentedVC()?.present(nav, animated: true)
    
    // Return true to customize product card click behavior
    return true
}

Use the host app navigation controller to push the host app page

When the SDK fullscreen player is displayed, the host app's navigation controller resides beneath it. We offer APIs to transition the fullscreen player to a floating player or to close the fullscreen player altogether, enabling users to view the host app page. Please refer to the following code snippets for more details:

func fireworkShopping(
    _ fireworkShopping: FireworkVideoShopping,
    didTapProductVariant item: SelectedProductVariant,
    forVideo video: VideoDetails
) -> Bool {
    do {
        try PictureInPictureController.start()
    } catch {
        FireworkVideoSDK.dismissFullScreenPlayer()
    }
    if let nav = FireworkVideoSDK.getHostAppNavigationController() {
        // The following PDP view controller is a sample.
        // Please create your own PDP view controller.
        let pdpVC = UIViewController()
        nav.pushViewController(pdpVC, animated: true)
        return true
    }
    return false
}

FireworkVideoSDK.getHostAppNavigationController is added in V1.27.6. For older versions, you could use the following codes to get the host navigation controller:

func getAppKeyWindow() -> UIWindow? {
    for scene in UIApplication.shared.connectedScenes {
        if let currentSene = scene as? UIWindowScene {
            for window in currentSene.windows where window.isKeyWindow {
                return window
            }
        }
    }
    return nil
}

func getNavigationController(base: UIViewController) -> UINavigationController? {
    if let nav = base as? UINavigationController {
        return nav
    }

    if let tab = base as? UITabBarController, 
        let selected = tab.selectedViewController {
        return getNavigationController(base: selected)
    }

    return base.navigationController
}

func getHostAppNavigationController() -> UINavigationController? {
    guard let rootViewController = getAppKeyWindow()?.rootViewController else {
        return nil
    }

    guard let nav = getNavigationController(base: rootViewController) else {
        return nil
    }

    return nav
}

func fireworkShopping(
    _ fireworkShopping: FireworkVideoShopping,
    didTapProductVariant item: SelectedProductVariant,
    forVideo video: VideoDetails
) -> Bool {
    do {
        try PictureInPictureController.start()
    } catch {
        FireworkVideoSDK.dismissFullScreenPlayer()
    }
    if let nav = getHostAppNavigationController() {
        // The following PDP view controller is a sample.
        // Please create your own PDP view controller.
        let pdpVC = UIViewController()
        nav.pushViewController(pdpVC, animated: true)
        return true
    }
    return false
}

The above code snippets are based on fireworkShopping(_:didTapProductVariant:forVideo:). But they are also applicable to other behavior delegate methods.

Last updated

Was this helpful?