Sparkling SDK - iOS API Reference

Native iOS SDK for hosting Sparkling content. For usage guide and concepts, see Containers. For the hybrid://... URL format, see Scheme.

Dependency (CocoaPods)

pod 'Sparkling', '2.0.0'
pod 'SparklingMacro', '2.0.0'

Initialization

import SparklingMacro

SPKServiceRegister.registerAll()
SPKExecuteAllPrepareBootTask()

SPKServiceRegister is defined in your app target (see the template under template/sparkling-app-template/ios/.../MethodServices/SPKServiceRegistrar.swift). SPKExecuteAllPrepareBootTask() is provided by SparklingMacro, so your app target must depend on SparklingMacro and import it before calling this function.

SPKRouter

Opens full-page Sparkling containers. See Containers — Full-page for usage guide.

MethodDescription
SPKRouter.open(withURL:context:)Creates and pushes a container onto the current navigation stack. Returns (container, success).
SPKRouter.create(withURL:context:frame:)Creates a container without presenting it. Returns a UIViewController & SPKContainerProtocol.
SPKRouter.close(container:)Pops or dismisses the given container.
SPKRouter.openInSystemBrowser(withURL:)Opens an HTTP/HTTPS URL in Safari.

SPKContainerView

Embeds Sparkling content as a subview. See Containers — Embedded for usage guide.

Method / PropertyDescription
SPKContainerView(frame:)Creates a container view with the given frame.
load(withURL:context:forceInitKitView:)Loads content from a scheme URL string.
load(withParams:context:forceInitKitView:)Loads content from an SPKHybridSchemeParam.
reload(context:)Reloads the current content.
handleViewDidAppear()Forwards appear event to Lynx runtime. Must be called by hosting VC.
handleViewDidDisappear()Forwards disappear event to Lynx runtime. Must be called by hosting VC.
send(event:params:callback:)Sends a custom event to the Lynx page.
config(withGlobalProps:)Sets initial global props.
update(withGlobalProps:)Updates global props at runtime.
sparkContentModeSizing mode: FixedSize (default), FixedWidth, FixedHeight, FitSize.
preferredLayoutSizeIntrinsic content size after loading (useful with non-fixed modes).
containerIDUnique identifier for this container instance.
loadStateCurrent loading state (NotLoad, Loading, Loaded, Failed).

SPKContext

Configuration object passed to both container types.

PropertyDescription
containerLifecycleDelegateDelegate conforming to SPKContainerLifecycleProtocol for loading callbacks.
loadingViewBuilderClosure that returns a custom loading view.
failedViewBuilderClosure that returns a custom error view.
naviBarCustom navigation bar (full-page containers only).
appThemeTheme configuration.
customUIElementsCustom Lynx UI elements to register.
extraDictionary of additional data passed to the container.

SPKContainerLifecycleProtocol

Callback protocol for observing container lifecycle events. Works with both container types.

CallbackDescription
container(_:didFinishLoadWithURL:)Content loaded successfully.
container(_:didLoadFailedWithURL:error:)Content failed to load.
containerDidFirstScreen(_:)First frame rendered.
container(_:didStartFetchResourceWithURL:)Resource fetch started.
containerDidUpdate(_:)Content updated.
container(_:didChangeIntrinsicContentSize:)Intrinsic content size changed (embedded mode).