> For the complete documentation index, see [llms.txt](https://docs.nubrick.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nubrick.app/start/install/ios.md).

# iOS

## サポート環境

* iOS 15.0 以上
* Xcode 16.1 以上

***

## Step 1. パッケージをインストールする

Swift Package ManagerまたはCocoaPodsが利用できます。

* [Swift Package Manager](https://github.com/plaidev/nubrick-ios/releases/latest)
* [CocoaPods](https://cocoapods.org/pods/Nubrick)

{% tabs %}
{% tab title="Swift Package Manager 🐦‍🔥" %}

1. Xcode上のメニューから、`File > Add Package Dependencies...` を選択する
2. `Search or Enter Package URL` の検索フィールドに次のURLを入力する
   1. `https://github.com/plaidev/nubrick-ios`
3. バージョンを選択し、インストールする
   1. ※基本的には最新バージョンを利用することを推奨しています。
      {% endtab %}

{% tab title="CocoaPods 🥥" %}
プロジェクトの Podfile に以下を追記します。

```ruby
target 'YourAppTarget' do
    pod 'Nubrick'
end
```

ターミナルから `pod install` を実行します。

```bash
pod install
```

{% hint style="warning" %}
ビルドに失敗した場合は、[Cocoapods エラーの解決方法](https://github.com/plaidev/nubrick-app-support/blob/main/ja/troubleshooting/cocoapods-error.md)を参照してください。
{% endhint %}
{% endtab %}
{% endtabs %}

## Step 2. Nubrick SDK を初期化する

{% hint style="warning" %}
`NubrickSDK.initialize(...)` は、`embedding` / `overlay` / `remoteConfig` / `dispatch` など他の API を使う前に、必ず 1 回だけ実行してください。\
SwiftUI では `@main` の `App` struct の `init()`、UIKit ではアプリ起動時（`AppDelegate` など）での初期化を推奨します。
{% endhint %}

### SwiftUI

`@main` の `init()` で SDK を初期化し、ルートビューを `NubrickProvider { ... }` で包んでオーバーレイ配信を表示できる状態にします。

```swift
import Nubrick
import SwiftUI

@main
@MainActor
struct YourApp: App {
    init() {
        NubrickSDK.initialize(projectId: "<YOUR_NUBRICK_PROJECT_ID>")
    }

    var body: some Scene {
        WindowGroup {
            NubrickProvider {
                ContentView()
            }
        }
    }
}
```

埋め込みコンポーネントは `NubrickSDK.embedding` で表示できます。

```swift
struct ContentView: View {
    var body: some View {
        VStack {
            NubrickSDK.embedding("ID_OF_YOUR_EMBEDDING")
                .frame(height: 240)
        }
    }
}
```

### UIKit

アプリ起動時に SDK を初期化し、`overlayViewController()` を画面ツリーに追加してオーバーレイ配信を表示できる状態にします。

```swift
import Nubrick
import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
    ) -> Bool {
        NubrickSDK.initialize(projectId: "<YOUR_NUBRICK_PROJECT_ID>")
        return true
    }
}

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        let overlay = NubrickSDK.overlayViewController()
        self.addChild(overlay)
        self.view.addSubview(overlay.view)
        overlay.didMove(toParent: self)

        let embeddingView = NubrickSDK.embeddingUIView("ID_OF_YOUR_EMBEDDING")
        self.view.addSubview(embeddingView)
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.nubrick.app/start/install/ios.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
