Skip to main content

iOS SDK

Your project must target iOS 10 or later. Swift projects should use Swift 4.2 or later, and CocoaPods 1.8.1 or later is required.
Add a package by selecting File → Add Packages… in Xcode’s menu bar.Search for the BoxoSDK using the repo’s URL:
https://github.com/Appboxo/boxo-ios-spm.git
Next, set the Dependency Rule to be Up to Next Major Version.Then, select Add Package.
Import Boxo SDK in your ViewController:
import BoxoSDK 
Initialize Boxo in your app by configuring a Boxo shared instance. Remember to replace client_id field with your client_id.
let config = Config(clientId: "client_id")
Boxo.shared.setConfig(config: config)
To launch the miniapp, you will need a UIViewController:

UIKit

To open miniapp write this code in your UIViewController:
let miniapp = Boxo.shared.getMiniapp(appId: "app_id")
miniapp.open(viewController: self)

SwiftUI

If you are using SwiftUI, you need to access the current UIViewController. There are many ways to obtain a UIViewController. Here is one of them:
struct ViewControllerFinder: UIViewControllerRepresentable {
    var onViewControllerFound: (UIViewController) -> Void

    func makeUIViewController(context: Context) -> UIViewController {
        let viewController = UIViewController()
        DispatchQueue.main.async {
            self.onViewControllerFound(viewController)
        }
        return viewController
    }

    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
...
struct ContentView: View {
    @State private var currentViewController: UIViewController?
    
    var body: some View {
        ViewControllerFinder { viewController in
            currentViewController = viewController
        }
        Button(action: {
            guard let currentViewController = currentViewController else { return }

            let miniapp = Boxo.shared.getMiniapp(appId: "app_id")
            miniapp.open(viewController: currentViewController)
        }) {
            Text("Open miniapp")
        }
    }
}
Configure BoxoSDK with these settings to customize behavior, language, and UI elements.

Language Configuration

Use it to provide language to miniapp. Default: ‘en’
let config = Config(clientId: "CLIENT_ID")
config.language = "en"
Boxo.shared.setConfig(config: config)
let config = Config(clientId: "CLIENT_ID")
config.setUserId(id: "HOST_APP_USER_ID") //will be used for the consent screen
Boxo.shared.setConfig(config: config)

Miniapp Menu Customization

let config = Config(clientId: "CLIENT_ID")
config.permissionsPage = false    // Hide "Settings"
config.showClearCache = false   // Hide "Clear Cache"
config.showAboutPage = false    // Show "About"
Boxo.shared.setConfig(config: config)
ParameterDescriptionDefault
permissionsPageSetting menu itemtrue
showClearCacheClear Cache menu itemtrue
showAboutPageAbout Miniapp menu itemtrue

Sandbox Mode Configuration

Control which miniapps are available in your development environment using the sandbox mode flag:
let config = Config(clientId: "CLIENT_ID")
config.sandboxMode = true
Boxo.shared.setConfig(config: config)
Behavior: Retrieve Miniapp List will return miniapps with the statuses listed below.
Sandbox ModeAvailable Miniapp StatusesUse Case
trueApproved + InTestingDevelopment environment - access to miniapps still in testing
falseApproved onlyProduction environment - only fully approved miniapps

Theme Configuration

Configure native component theming to match your app’s design system or respect user preferences. The SDK provides comprehensive theme support for:
  • Splash screens
  • Native UI components
  • System dialogs and alerts
Theme Options:
OptionDescription
SYSTEMAutomatically matches device theme
LIGHTForces light theme
DARKForces dark theme
Control theme behavior at both global and per-miniapp levels for maximum flexibility.Global Theme (Affects all miniapps)
let config = Config(clientId: "CLIENT_ID")
config.theme = .System
Boxo.shared.setConfig(config: config)
Per-Miniapp Theme Override
// Override theme for specific miniapp
miniapp.setConfig(config: MiniappConfig(theme: .Dark))
Handle authentication between your host app and miniapps:
miniapp.delegate = self
...
extension ViewController : MiniappDelegate {
  func onAuth(miniapp: Miniapp) {
    // 1. Fetch auth code from your backend
    val authCode = fetchAuthCodeFromBackend()

    // 2. Provide code to Miniapp
    miniapp.setAuthCode(authCode: authCode)
  }
}
When users log out of your host app, you must completely clear all miniapp session data
Boxo.shared.logout()
To listen for any URL change events:
miniapp.delegate = self
...
extension ViewController: MiniappDelegate {
    func didChangeUrlEvent(miniapp: Miniapp, url: URL) {
        // Listen for search URL
        if url.path.components(separatedBy: "/").contains("search") {
            print("Search url: \(url)")
        }
    }
}
Append additional query parameters to miniapp’s initial URL for passing contextual data. This enables:
  • User-specific data injection
  • Campaign tracking
  • Contextual deep linking
  • A/B testing configuration
let miniapp = Boxo.shared.getMiniapp(appId: "app_id")
let miniappConfig = MiniappConfig()
miniappConfig.setExtraParams(extraParams: ["user_id" : "u_12345", "campaign" : "summer_sale"])
miniapp.setConfig(config: miniappConfig)
Parameters will be automatically URL-encoded and appended as query parameters:
https://miniapp.example.com?user_id=u_12345&campaign=summer_sale
Establish two-way communication between your hostapp and miniapps using custom events. This system enables:
  • Real-time data exchange
  • User interaction tracking
  • Miniapp to host app callbacks
  • Dynamic content updates
miniapp.delegate = self
...
func didReceiveCustomEvent(miniapp: Miniapp, customEvent: CustomEvent) {
    customEvent.payload = [
        "status" : "success",
        "code" : 200
    ]

    // Send response back to miniapp
    miniapp.sendCustomEvent(customEvent: customEvent)
}
You can extend the miniapp’s native menu by adding your own custom action item by defining .setCustomActionMenuItemImage
let miniapp = Boxo.shared.getMiniapp(appId: "app_id")
let miniappConfig = MiniappConfig()
miniappConfig.setCustomActionMenuItemImage(image: UIImage(named: "ic_custom_action_button"))
miniapp.setConfig(config: miniappConfig)
miniapp.delegate = self
...
extension ViewController : MiniappDelegate {
    func didSelectCustomActionMenuItemEvent(miniapp: Miniapp) {
        // do something
    }
}
Control Visibility:
// Hide the item
miniapp.hideCustomActionMenuItem()

// Show when needed
miniapp.showCustomActionMenuItem()
Fetch the complete catalog of available miniapps with detailed metadata. This operation returns:
  • Basic miniapp information (id, name, description)
  • Logo
  • Category
Boxo.shared.getMiniapps { miniapps, error in
    miniapps.forEach { data in
        print(data.appId)
        print(data.name)
        print(data.longDescription)
        print(data.logo)
        print(data.category)
    }
}
When a miniapp is launched, Boxo displays a splash screen while the content is loading. You can customize the splash screen background color and the loading progress indicator for both light and dark themes.

Background Colors

Use the splashBackgroundColors property to configure splash background colors:
let config = Config(clientId: "CLIENT_ID")
config.splashBackgroundColors = SplashBackgroundColors(light: UIColor.white, dark: UIColor.black)
Boxo.shared.setConfig(config: config)

Progress Bar Colors

Use the progressBarColors property to configure progress bar colors:
let config = Config(clientId: "CLIENT_ID")
config.progressBarColors = ProgressBarColors(lightIndicator: UIColor.red, lightTrack: UIColor.yellow, darkIndicator: UIColor.green, darkTrack: UIColor.orange)
Boxo.shared.setConfig(config: config)

Splash Behavior

By default, the splash screen is shown automatically and hides when approximately 50% of the web content has loaded.You can control this behavior using MiniappConfig. For example, to disable the splash screen entirely:
let miniapp = Boxo.shared.getMiniapp(appId: "app_id")
            
let miniappConfig = MiniappConfig()
miniappConfig.enableSplash(isSplashEnabled: false)
miniapp.setConfig(config: miniappConfig)

miniapp.open(viewController: self)
Customize the animation effects to enhance the user experience by setting the appropriate page transition animation when opening a miniapp.You can choose from the following page animations:
  • LEFT_TO_RIGHT - The miniapp slides in from the left side of the screen to the right.
  • RIGHT_TO_LEFT - The miniapp slides in from the right side of the screen to the left.
  • BOTTOM_TO_TOP- The miniapp slides in from the bottom of the screen to the top.
  • TOP_TO_BOTTOM - The miniapp slides in from the top of the screen to the bottom.
  • FADE_IN - The miniapp fades in gradually from completely transparent to opaque.
The BOTTOM_TO_TOP animation is the default page transition effect. You can easily change the animation to any of the other available options based on the user experience you want to provide.
let config = MiniappConfig()
config.pageAnimation = PageAnimation.RIGHT_TO_LEFT

let miniapp = Boxo.shared.getMiniapp(appId: "app_id")
miniapp.setConfig(config: config)
miniapp.open(viewController: self)
Miniapp lifecycle events allow you to monitor key activities, such as onLaunch, onResume, onPause, onClose, and onError. These events help track the miniapp’s behavior throughout its usage lifecycle.
miniapp.delegate = self
...
extension ViewController: MiniappDelegate {
    func onLaunch(miniapp: Miniapp) {
        print("onLaunchMiniapp: \(miniapp.appId)")
    }

    func onResume(miniapp: Miniapp) {
        print("onResumeMiniapp: \(miniapp.appId)")
    }

    func onPause(miniapp: Miniapp) {
        print("onPauseMiniapp: \(miniapp.appId)")
    }

    func onClose(miniapp: Miniapp) {
        print("onCloseMiniapp: \(miniapp.appId)")
    }

    func onError(miniapp: Miniapp, message: String) {
        print("onErrorMiniapp: \(miniapp.appId) message: \(message)")
    }

    func onUserInteraction(miniapp: Miniapp) {
        print("onUserInteractionMiniapp: \(miniapp.appId)")
    }
}