Event handler

    Event handler


    Article summary

    Through the ShopLiveShortformReceiveHandlerDelegate function, notifications from Shoplive Shortform are delivered to the client and process as needed.

    protocol ShopLiveShortformReceiveHandlerDelegate : AnyObject  {
        @objc optional func handleShare(shareMetadata : ShopLiveShareMetaData)
        @objc optional func onError(error: Error)
        @objc optional func onEvent(command: String, payload: String?)
        @objc optional func onDidDisAppear()
        @objc optional func onDidAppear()
        @objc optional func handleProductItem(shortsId : String, shortsSrn : String, product : ProductData)
        @objc optional func handleProductBanner(shortsId : String, shortsSrn : String, scheme : String, shortsDetail : ShortsDetailData)
    }
    
    //Adopting the handler.
    
    
    class ViewController : ShopLiveShortformReceiveHandlerDelegate { 
      
      override func viewDidLoad(){
        super.viewDidLoad()
        ShopLiveShortform.Delegate.setDelegate(self)
      }
      
    }


    onEvent

    Shoplive Shortform provides the onEvent(command: String, payload: String?) callback function that allows you to handle various events directly.


    onError

    Shoplive provides the onError(error: Error) callback function that allows direct handling of errors occurring in Shoplive Shortform.

    ShopLiveCommonError

    Property name

    Type

    Description

    code

    Int

    A Shoplive error code

    message

    String?

    An error message

    error

    Error?

    The original error message provided by operating system (if exists)

    class ViewController : UIViewController, ShopLiveShortformReceiveHandlerDelegate { 
    	func onError(error : Error) {
      	if let error = error as? ShopLiveCommonError {
        	if let code = error.code { 
          	//do something
          }
          if let message = error.message {
          	//do something
          }
          if let error = error.error { 
          	//do something
          }
        }
      }
    }


    handleShare

    With the handleShare(shareMetaData: ShopLiveShareMetaData), you can develop direct sharing functionality in Shoplive Shortform.

    ShopLiveMetaData

    Property name

    Type

    Description

    shortsId

    String?

    Shortform unique identifier

    shortsSrn

    String?

    ID containing unique information for Shortform

    title

    String?

    Shortform title (for og tag purposes)

    descriptions

    String?

    Shortform description (for og tag purposes)

    thumbnail

    String?

    Shortform thumbnail (for og tag purposes)

    class ViewController : ShopLiveShortformReceiveHandlerDelegate { 
      func handleShare(shareMetaData: ShopLiveShareMetaData) { 
        //Do something
      }
    }


    onDidAppear

    With the onDidAppear(), you can receive the Shoplive Shortform's Full-type screen open event.

    class ViewController : ShopLiveShortformReceiveHandlerDelegate { 
      func onDidAppear() { 
        //ex) stop ListView player when entering Shortform detail
        builder?.disablePlayVideos()
      }
    }


    onDidDisAppear

    With the onDidDisAppear(shareUrl: String), you can receive the Shoplive Shortform's Full-type screen close event.

    class ViewController : ShopLiveShortformReceiveHandlerDelegate { 
      func onDidDisAppear(shareUrl: String) {
        //ex) play ListView players when ListView reappeared
        builder?.enablePlayVideos()
      }
    }


    ShopLiveShortformDetailHandlerDelegate

    Through the ShopLiveShortformDetailHandlerDelegate function, notifications from Shoplive Shortform are received by the client and processed as necessary.

    handleProductItem

    With the handleProductItem(shortsId: String, shortsSrn: String, product: Product), you can develop a direct product click feature in Shoplive Shortform.

    class ViewController : ShopLiveShortformNativeHandlerDelegate { 
      func handleProductItem(shortsId : String, shortsSrn : String, product : Product) { 
        //ex) Show preview when product is clicked with sku
        ShopLiveShortform.showPreview(requestData: ShopLiveShortformRelatedData(sku: product.sku))
      }
    }

    Product

    Property name

    Type

    Description

    brand

    String?

    Brand information of the product

    currency

    String?

    Currency of the product

    description

    String?

    Description of the product

    discountPrice

    Double?

    Discounted price of the product

    discountRate

    Double?

    Discount percentage of the product

    imageUrl

    String?

    Product image URL

    name

    String?

    Product name

    originalPrice

    Double?

    Regular price of the product

    productId

    String?

    Unique ID of the product, automatically issued upon product registration

    showPrice

    Boolean

    Displayed price of the product

    sku

    String?

    Unique SKU information of the product

    url

    String?

    URL of the product's detailed page

    handleProductBanner

    With the handleProductBanner(shortsId: String, shortsSrn: String, scheme: String, shortsDetail: ShortsDetail), you can develop a direct product banner click feature in Shoplive Shortform.

    class ViewController : ShopLiveShortformNativeHandlerDelegate { 
      func handleProductBanner(shortsId : String, shortsSrn : String, scheme : String, shortsDetail : ShortsDetail) { { 
        
      }
    }