⌘K

Nativeblocks Core

Nativeblocks is a server-driven UI SDK that dynamically generates user interfaces and their associated functionality based on a JSON configuration received from a backend service. This framework enables flexible and dynamic application design without requiring constant app updates.


Key Features

  • Dynamic UI Rendering: Generates user interfaces dynamically based on JSON payloads.
  • Flexible Configuration: Supports multiple editions, including cloud-based and community-based configurations.
  • Actionable Components: Provides seamless integration of actions, events, and triggers.
  • Scalable: Suitable for large-scale applications with modular UI components.

Example Workflow

  1. Initialization: The SDK is initialized with either a cloud or community edition using NativeblocksManager.initialize.
  2. Scaffold Fetching: Frames are registered and scaffold metadata is retrieved.
  3. Rendering: Components such as blocks and actions are dynamically rendered and executed.
  4. Lifecycle Management: Logging, synchronization, and cleanup are handled by the SDK.

Get started

Install or update Xcode to its latest version.

Make sure that your project meets these requirements:

  • Uses Swift 5.0 or higher
  • Uses SwiftUI for UI development
  • Use iOS 15.0 or above

Adding Nativeblocks to Your Project

Add the following dependency to your Package.swift or Xcode project:

.package(url: "https://github.com/nativeblocks/nativeblocks-ios-sdk", from: "1.2.0")

Initialize the SDK

Let's get started by initializing the SDK. You can do this in the App struct or provide via dependency injection.

1. cloud Edition

Cloud-based configuration with an endpoint, API key, and development mode option.

NativeblocksManager.initialize(
    edition: .cloud(
        endpoint: NATIVEBLOCKS_API_URL,
        apiKey: NATIVEBLOCKS_API_KEY,
        developmentMode: true
    )
)

2.community Edition

Community-based configuration using frame-url. The frame data is a dictionary where each key is a route and each value is the corresponding frame URL.

NativeblocksManager.initialize(
    edition: .community(frameData: [
        "/": "https://frame-url"
    ])
)

And call destroy function on applicationWillTerminate

App.swift
class AppDelegate: NSObject, UIApplicationDelegate {
    func applicationWillTerminate(_ application: UIApplication) {
        NativeblocksManager.getInstance().destroy()
    }
}

To initialize the SDK, three parameters are needed:

  • API Url (you can get specific version from support team)
  • API Key (Once you created a new project in the Nativeblocks, you can get the API key from project information)
  • DevelopmentMode (by enabling this option you can see the changes immediately, but for the production usage, this should be false)

Once the SDK is initialized, configure the main content of your app to use NativeblocksFrame to load and manage blocks.

App.swift
struct ContentView: View {
    var body: some View {
        NativeblocksFrame(
            route: "/",
            routeArguments: [:],
            loading: {
                AnyView(NativeblocksLoading())
            },
            error: { message in
                AnyView(NativeblocksError(message: message))
            }
        )
    }
}

The core SDK itself does not have any integrations. All integrations need to be registered in the Nativeblocks integration marketplace and provided to the SDK.

The current version of the SDK supports the following integrations:

  • Block
  • Action & ActionContractor
  • Logger

Block

To provide a custom block, use the following method:

NativeblocksManager.getInstance().provideBlock(
    blockKeyType: "INTEGRATION_UNIQUE_KEY_TYPE",
    block: CustomBlockInstance()
)

Action

To provide a custom action, use the following method:

NativeblocksManager.getInstance().provideAction(
    actionKeyType: "INTEGRATION_UNIQUE_KEY_TYPE",
    action: CustomActionInstance()
)
NativeblocksManager.getInstance().provideActionContractor(
    actionContractor: CustomActionContractorInstance()
)

Logger

To provide a custom logger, use the following method:

NativeblocksManager.getInstance().provideEventLogger(
    loggerType: "INTEGRATION_UNIQUE_KEY_TYPE",
    logger: CustomLoggerInstance()
)