Hybrid Integration

    Hybrid Integration


    Article summary

    Integrate with code

    CocoaPods

    Add the below code to Podfile.

    source 'https://github.com/CocoaPods/Specs.git'
    
        # Match the Version with the Project's Minimum Supported Version
        # Shoplive iOS SDK requires iOS 11.0 or later.
        platform :ios, '11.0'
        use_frameworks!
    
        # Set the Project Target for Shoplive iOS SDK Installation
        target 'ShortformProj' do
            pod 'ShopliveShortformSDK', '1.5.5'
          	pod 'ShopliveSDKCommon', '1.5.5'
        end

    Swift Package Manager

    Add the following contents to Package Dependencies.

    dependencies: [
        .package(url: "https://github.com/shoplive/shortform-ios", .exact(from: "1.5.5")),
        .package(url: "https://github.com/shoplive/common-ios", .exact(from: "1.5.5"))
    ]

    ❗️

    Delete the cache if installation is failed

    Execute the following command in the terminal to delete the cache.

    rm -rf ~/Library/Caches/org.swift.swiftpm
    rm -rf ~/Library/org.swift.swiftpm


    Web integration

    To enable Shortform service, web integration needs to be prioritized. Please refer to the following link for Shortform web integration.


    Apply native code to Web View

    Add the following code to the customer's web UIViewController. Refer to the Shorform iOS SDK Handler guide.

    import ShopLiveShortformSDK
    
    class CustomerViewController: UIViewController {
        ...
        override func viewDidLoad() {
            super.viewDidLoad()
            ShopLiveShortform.BridgeInterface.connect(webview) // Required
            ShopLiveShortform.ShortsReceiveInterface.setHandler(self) // Required
        }
        ...
    }
    
    extension CustomerViewController: ShopLiveShortformReceiveHandlerDelegate {
        func handleShare(shareUrl: String) {
          // Do something
        }
        
        func onError(error: Error) {
          // Do something
        }
        
        func onEvent(command: String, payload: String?) {
          // Do something
        }
        
        func onDidDisAppear() {
          // Do something
        }
        
        func onDidAppear() {
          // Do something
        }
    }

    ShopLiveShortform.BridgeInterface

    Connecting WebView to the BridgeInterface alone provides the following functionalities:

    • Automatically closes the preview when exiting the product screen.

    • Shortform preview, view, and close actions are operational.

    // Connect Webview to BridgeInterface 
    ShopLiveShortform.BridgeInterface.connect(webview) // Required

    ShopLiveShortform.ShortsReceiveInterface

    If you set up the ReceiveInterface handler on the customer's web UIViewController, you can utilize the following callbacks

    public protocol ShopLiveShortformReceiveHandlerDelegate: AnyObject {
        // Delivers the share URL when the share button is pressed.
        func handleShare(shareUrl: String)
        func handleShare(shareMetadata: ShopLiveShareMetaData)
        // Delivers an error if one occurs. By default, error is passed as ShopLiveCommonError:Error.
        func onError(error: Error)
        // Delivers events that occur in the shortform.
        func onEvent(command: String, payload: String?)
        // Delivers the close event of the shortform screen.
        func onDidDisAppear()
        // Delivers the open event of the shortform screen.
        func onDidAppear()
        // Delivers the product click event.
        func handleProductItem(shortsId: String, shortsSrn: String, product: ProductData)
        // Delivers the product banner click event.
        func handleProductBanner(shortsId: String, shortsSrn: String, scheme: String, shortsDetail: ShortsDetailData)
    }


    What's Next