> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/roboflow/roboflow-jp/deploy/sdks/ios-sdk.md).

# iOS SDK

Roboflow Mobile iOS SDK は、より高速な推論や、拡張現実のような新しい機能、能力、ユースケースを解放するために、エッジ（iPad または iPhone）上でモデルを動作させる必要がある iOS アプリケーションを開発している場合に最適な選択肢です。

カスタムのコンピュータビジョンモデルを組み込んだネイティブモバイルアプリケーションにより、開発者はアプリに「見る力」を与えることができます。

## タスクのサポート

ホストされた API では、以下のタスクタイプがサポートされています:

| タスクタイプ           | iOS SDK デプロイメントでサポート |
| ---------------- | -------------------- |
| オブジェクト検出         | ✅                    |
| 分類               |                      |
| インスタンスセグメンテーション  | ✅（iOS 18 以上）         |
| セマンティックセグメンテーション |                      |

### CoreML エクスポート互換性

以下のモデルアーキテクチャは、オンデバイスデプロイメント用の CoreML（`.mlpackage`）エクスポートをサポートしています:

| モデル      | CoreML エクスポート |
| -------- | ------------- |
| RF-DETR  | ✅             |
| YoloLite | ✅             |
| 分類モデル    | ✅             |

## iOS デバイスにモデルをデプロイする

### サポートされるハードウェアとソフトウェア

すべての iOS デバイスはオンデバイス推論をサポートしていますが、iPhone 8（A11 Bionic プロセッサ）より古いものは、エネルギー効率の低い gpu エンジンにフォールバックします。

Roboflow では、最低 iOS バージョン 15.4 が必要です（インスタンスセグメンテーションモデルの場合は 18.0）。

## プロトタイピング

次の項目に対して開発できます: [Roboflow Serverless Hosted API](https://docs.roboflow.com/deploy/serverless)。これはオンデバイス推論と同じ学習済みモデルを使用します。

## インストール

* インストール [CocoaPods](https://guides.cocoapods.org/using/getting-started.html) | [トラブルシューティングガイド](https://guides.cocoapods.org/using/troubleshooting#installing-cocoapods)

「CocoaPods は Ruby で構築されており、macOS に標準で付属する Ruby でインストールできます。Ruby バージョンマネージャーを使うこともできますが、何をしているか分かっている場合を除き、macOS にある標準の Ruby を使うことを推奨します。デフォルトの Ruby を使う場合、gem をインストールするときに `sudo` を使用する必要があります。（ただし、これは gem のインストール中だけの問題です。）」 - [CocoaPods](https://guides.cocoapods.org/using/getting-started.html)

「Sudo なし」のインストールは、このプロセスで RubyGems に管理者権限を付与したくない場合の選択肢です。ただし、 `sudo` インストールのほうが一般的であることに注意してください。

次を入力して CocoaPods が正常にインストールされていることを確認してください `pod --version` を Terminal で。

### Roboflow CocoaPod のインストール

まず、 `pod init` をプロジェクトディレクトリで実行します。

次を確認してください `Podfile` が次を指定していること `platform :ios, '15.4'`

次に、 `pod 'Roboflow'` を追加します `Podfile`.

XCode Command Line Tools がインストールされていない場合は、次を実行してください `xcode-select --install` を Terminal で。

すると次が返されます: `xcode-select: error: command line tools are alreadyinstalled, use "Software Update" to install updates` Command Line Tools がすでにシステムに存在する場合。

最後に、 `pod install` を実行し、生成された `.xcworkspace` ファイルを [XCode](https://developer.apple.com/xcode/).

![Podfile のインストール成功後の Terminal](/files/64434150043020401a8a6b8acf7a365391cb367e)

![Podfile のインストール成功後のプロジェクトディレクトリ](/files/2da66994d2a7ffc71b12b5f5c9d9f4c1888bcb6e)

* これが次のエラーを返す場合: "You may have encountered a bug in the Ruby interpreter or extension libraries," まず次を実行してください `brew install cocoapods`、その後次を実行してください `pod install` を実行し、生成された `.xcworkspace` XCode でファイルを開きます。
  * 次を入力して CocoaPods が正常にインストールされていることを確認してください `pod --version` を Terminal で。

### Swift で Roboflow を使う

次へ移動します `.xcworkspace` XCode でファイルを開きます。

![](/files/2295650ae62d8e5dc623df8b7a1b2679dd1b7fdd)

次に、次を追加して Roboflow をインポートします `import Roboflow`。を `.xcworkspace` ファイルに。

その後、次を使って Roboflow API のインスタンスを作成します `let rf = Roboflow(apiKey: "API_KEY")`。 `modelVersion`については、 `YOUR-MODEL-VERSION-#` を、モデルのバージョン番号の整数値に置き換えてください。

#### プロジェクト情報の確認

**Completion Handler の使用:**

```swift
import Roboflow
...
//API キーで初期化
let rf = RoboflowMobile(apiKey: "API_KEY")
var model: RFModel?
...

//model はあなたのモデルのプロジェクト名です
rf.load(model: "YOUR-MODEL-ID", modelVersion: YOUR-MODEL-VERSION-#) { [self] model, error, modelName, modelType in
    if error != nil {
        print(error?.localizedDescription as Any)
    } else {
        model?.configure(threshold: threshold, overlap: overlap, maxObjects: maxObjects
                            processingMode: .performance or .balanced or .quality, // instance seg
                            maxNumberPoints: マスク処理ポイントの最大数) // instance seg
        self.model = model
    }
    
}
...

//model?.detect は UIImage を受け取り、それに対して推論を実行します
let img = UIImage(named: "example.jpeg") // または CVPixelBuffer
model?.detect(image: img!) { predictions, error in
    if error != nil {
        print(error)
    } else {
        print(predictions)
    }
}
```

**非同期での使用:**

非同期で使用するには、Roboflow モデルを非同期ブロック内で呼び出す必要があります。

```swift
import Roboflow
...
//API キーで初期化
let rf = RoboflowMobile(apiKey: "API_KEY")
...

//model はあなたのモデルのプロジェクト名です
let (model, loadingError, modelName, modelType) = await rf.load(model: "YOUR-MODEL-ID", modelVersion: YOUR-MODEL-VERSION-#)
model!.configure(threshold: threshold, overlap: overlap, maxObjects: maxObjects)
...

//model?.detect は UIImage を受け取り、それに対して推論を実行します
let img = UIImage(named: "example.jpeg")
let (predictions, predictionError) = await model!.detect(image: img!)
print(predictions)
```

**予測の形式:**

```
x:Float //オブジェクトの中心 x
y:Float //オブジェクトの中心 y
width:Float
height:Float
className:String
confidence:Float
color:UIColor
box:CGRect
points:[CGPoint] // instance segmentation models のみ
```

[CGRect](https://developer.apple.com/documentation/corefoundation/cgrect)

### ネイティブ Swift の例

その [roboflow-ios-starter](https://github.com/roboflow/roboflow-ios-starter) アプリは、roboflow モデルを使ってリアルタイムの iOS アプリを作成するための優れた出発点です。カメラ設定、モデルの読み込みと処理、そして object-detection と instance segmentation モデルの両方に対応した出力描画コードが含まれています。

### React Native Expo アプリの例

ここでは、React Native を使ってこの SDK を expo アプリに統合する例も提供しています。独自の下流アプリケーションを構築する際の参考になるでしょう。

次の両方があることを確認してください [Expo](https://docs.expo.dev/) と [CocoaPods](https://guides.cocoapods.org/using/getting-started.html) がインストールされています。

* `expo-cli` は次の Node.js バージョンをサポートしています: `>=12.13.0 <15.0.0` （Maintenance LTS）および `>=16.0.0 <17.0.0` （Active LTS）
* yarn パッケージは Node.js 用にインストールする必要があります（`npm install -g yarn`)

{% embed url="<https://github.com/roboflow-ai/RoboflowExpoExample>" %}

### 例の iOS アプリケーション - CashCounter

ダウンロード [CashCounter](https://apps.apple.com/app/roboflow-cash-counter/id1633812788)、US コインと紙幣を数える例の iOS アプリです。iPhone にコンピュータビジョンモデルをデプロイする方法の例として使用できます。バウンディングボックスの可視化、FPS、オブジェクトカウント、画像アップロードなどの例が表示されます。


---

# 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:

```
GET https://docs.roboflow.com/roboflow/roboflow-jp/deploy/sdks/ios-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
