Developing Kanzi applications for iOS¶
You can use the Kanzi application framework (appfw) to develop Kanzi applications for iOS. You write application and plugin code in C++ and build the application using CMake and Xcode. Before you begin, check the Requirements for iOS application development with Kanzi.
Kanzi Studio generates a ready-made iOS CMake configuration and a helper script for generating the Xcode project when you create a project using one of these templates:
Application
Application with data source plugin
Application with Kanzi Engine plugin
iOS project structure¶
The <ProjectName>/Application/configs/platforms/ios/ directory contains:
CMakeLists.txt– applies iOS and Xcode-specific settings to the executable target. This includes:XCODE_ATTRIBUTE_INSTALL_PATHset tooutput. Combined withDSTROOT=$(PROJECT_DIR)passed toxcodebuild install, this places the built application in<Application>/output/.XCODE_EMBED_FRAMEWORKS– embeds the Vulkan and MoltenVK frameworks into the application bundle.XCODE_EMBED_RESOURCES– embeds the kzb binary files that you export from Kanzi Studio.
Info.plist– defines the launch screen, supported orientations, and theUIApplicationSceneManifestthat wires the application to theSceneDelegateprovided by the iOS application shell.Assets.xcassets– contains the application icon.src/– the iOS application shell that hostsKanziView:main.m–UIApplicationMainentry point.app_delegate.h,m–UIApplicationDelegatethat selects the default scene configuration.scene_delegate.h,m–UIWindowSceneDelegatethat creates theUIWindowand installs the rootViewController.view_controller.h,m– fullscreenUIViewControllerwhose root view is aKanziView. This is where you embed the Kanzi view inside the iOS view hierarchy.
The Application folder also contains generate_cmake_xcode_ios_project.sh, which generates the Xcode project using the CMake Xcode generator and the Kanzi iOS toolchain.
The iOS platform package ships KanziView and KanziViewRepresentable in the KanziAppFwKit XCFramework. The generated CMake configuration links your application target against KanziAppFwKit and embeds the XCFramework in the application bundle.
To learn how to build and deploy your application to an iOS device, see Deploying Kanzi applications to iOS.
KanziView¶
KanziView is a UIKit UIView subclass that hosts Kanzi rendering inside an iOS view hierarchy. You place KanziView anywhere in your UIKit view hierarchy alongside native iOS content.
In addition to rendering, KanziView:
Drives the Kanzi application lifecycle. Attaching
KanziViewto a window starts the Kanzi application. DetachingKanziViewshuts the application down.Pauses Kanzi when the iOS application resigns active state, and resumes Kanzi when the application becomes active again.
Forwards touch events to Kanzi.
Note
Only one KanziView can exist in a process at a time.
Application factory¶
KanziView requires a C++ createApplication() factory function that returns the Application instance to run, with the same signature as on every other Kanzi platform. For example:
#include <kanzi/core.ui/application/application.hpp>
class MyApplication : public kanzi::Application
{
// Override onProjectLoaded, onConfigure, and so on.
};
kanzi::Application* createApplication()
{
return new MyApplication();
}
Link this translation unit into your application target alongside KanziAppFwKit. KanziAppFwKit calls createApplication() once per view attach and deletes the returned instance when the view detaches.
Note
On iOS, Kanzi does not receive command-line arguments — KanziAppFwKit owns the application entry point and calls createApplication() without argc/argv. As a result, SystemProperties is default-initialized. To configure your application, use application.cfg or override Application::onConfigure. See Application configuration reference.
Adding a Kanzi view in UIKit¶
To add a Kanzi view to a UIKit application, import KanziAppFwKit and place a KanziView in your view hierarchy. You can instantiate KanziView:
From code:
Override
loadView(orviewDidLoad) in yourUIViewController.Assign a
KanziViewinstance.
#import <kanzi_view.h> @implementation ViewController - (void)loadView { KanziView* kanziView = [[KanziView alloc] initWithFrame:CGRectZero]; kanziView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.view = kanziView; } @end
import KanziAppFwKit import UIKit class ViewController: UIViewController { override func loadView() { let kanziView = KanziView(frame: .zero) kanziView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view = kanziView } }
From a storyboard or XIB:
In Interface Builder, drop a plain
UIViewonto your scene.In the Identity Inspector, set the Class to
KanziView.Set the Module to
KanziAppFwKit.
KanziViewinitializes frominitWithCoder:, so storyboard-loaded views work the same as code-instantiated ones.
Adding a Kanzi view in SwiftUI¶
To embed Kanzi content in a SwiftUI hierarchy, use KanziViewRepresentable, a UIViewRepresentable wrapper around KanziView. Place it like any other SwiftUI view — you can size it, position it, and compose it with native SwiftUI views.
import KanziAppFwKit
import SwiftUI
struct ContentView: View {
var body: some View {
KanziViewRepresentable()
.ignoresSafeArea()
}
}
See also¶
Deploying Kanzi applications to iOS