iOS

アカウント作成がまだの方は、最初に下記を参考の上、作成をお願いします。

https://docs.nativebrik.com/start/quickstart/account

System Requirements

  • minimum iOS version: 15.0 or higher

  • minimum XCode version: 15 or higher

  • minimum Swift version: 5.9 or higher

Step 1. Install Nativebrik SDK to your app

Nativebrik SDK can be installed using some options below:

  • With Swift Package Manager

  • With CocoaPods

Swift Package Manager

Nativebrik is available through Swift Package Manager. To install it, follow the steps below:

  1. In Xcode, install the SDK by navigating to File > Add Packages

  2. In the prompt that appears, select the Nativebrik SDK GitHub repository:

SDK Repository

https://github.com/plaidev/nativebrik-sdk
  1. Select the version of Nativebrik SDK you want to use. For new projects, we recommend using the newest version of Nativebrik SDK.

  2. Once you're finished, Xcode will begin resolving your package dependencies and downloading them in the background.

CocoaPods

Nativebrik is available through CocoaPods. To install it, simply add the following line to your Podfile:

project/Podfile

target 'YourAppTarget' do
    pod 'Nativebrik'
end

and run pod install from the terminal.

pod install

Step 2 (SwiftUI). Initialize Nativebrik SDK in your app

Import the Nativebrik module in your root swfit code:

import SwiftUI
import Nativebrik

Initialize Nativebrik SDK in your root App struct:

import SwiftUI
import Nativebrik

let nativebrik = {
    return NativebrikClient(projectId: "<YOUR_NATIVEBRIK_PROJECT_ID>")
}()

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        NSSetUncaughtExceptionHandler { exception in
            nativebrik.experiment.record(exception: exception)
        }
        return true
    }
}

@main
struct YourApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    var body: some Scene {
        WindowGroup {
            NativebrikProvider(client: nativebrik) {
                ContentView()
            }
        }
    }
}

and in #Preview, add NativebrikProvider to it if needed:

struct ContentView: View {
    @EnvironmentObject var nativebrik: NativebrikClient
    var body: some View {
        VStack {
            nativebrik
                .experiment
                .embedding("ID_OF_YOUR_EMBEDDING")
                .frame(height: 240)
        }
    }
}

#Preview {
    NativebrikProvider(client: nativebrik) {
        ContentView()
    }
}

Step 2 (UIKit). Initialize Nativebrik SDK in your app

Import the Nativebrik module in your root swfit code:

import UIKit
import Nativebrik

Initialize Nativebrik SDK in your AppDelegate:

import UIKit
import Nativebrik

let nativebrik = {
    return NativebrikClient(projectId: "<YOUR_NATIVEBRIK_PROJECT_ID>")
}()

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        NSSetUncaughtExceptionHandler { exception in
            // report crash to nativebrik, to track it
            nativebrik.experiment.record(exception: exception)
        }
        
        return true
    }
}

And Add Nativebrik's OverlayViewController to your root UIViewController

import UIKit
import Nativebrik

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        NSSetUncaughtExceptionHandler { exception in
            nativebrik.experiment.record(exception: exception)
        }
        return true
    }
}

class ViewController: UIViewController {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    override func viewDidLoad() {
        super.viewDidLoad()

        let overlay = nativebrik.experiment.overlayViewController()
        self.addChild(overlay)
        self.view.addSubview(overlay.view)
    }
}

Last updated