> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kleep.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# モバイル SDK - iOS

**Github リポジトリ:** [https://github.com/KlipFit/kleep-spm](https://github.com/KlipFit/kleep-spm)

## インストール

***

このプロセスは、プロジェクトに SDK を初めてインストールする際に一度だけ行う必要があります。その後のアップデート手順については、**アップデート**セクションを参照してください。

1. 次のパッケージを追加してください: [https://github.com/KlipFit/kleep-spm](https://github.com/KlipFit/kleep-spm)
2. 依存関係ルールを「次のメジャーバージョンまで」に変更してください

## 権限

***

info.plist のプロジェクトに次の権限を追加してください: **NSCameraUsageDescription**

## 使用方法

***

### メソッド 1: `requestSize`

このメソッドは CTA のロジックを実装するために使用します。

| パラメータ            | 優先度  | 説明                          |
| ---------------- | ---- | --------------------------- |
| **productID**    | *必須* | 商品 ID                       |
| **retailerName** | 必須   | 小売業者名                       |
| **customerID**   | *任意* | 分析に使用する CRM 識別子             |
| **trackingID**   | *任意* | 外部トラッキングソリューションで使用するユーザー ID |

**ロジック スキーマ**

このスキーマは、Kleep を開く CTA の更新方法を説明しています。

[https://www.figma.com/board/BlurZ01lR3JBQZeTUU98TE/Mobile---CTA-Logic?node-id=0-1\&t=ccXWciNziIdfhgew-1](https://www.figma.com/board/BlurZ01lR3JBQZeTUU98TE/Mobile---CTA-Logic?node-id=0-1\&t=ccXWciNziIdfhgew-1)

**実装例**

```swift theme={null}
import Klipfit

struct ContentView: View {
    @State var isOpenView = false
        
    var body: some View {
        VStack {
            Spacer()
            Button("Open Kleep") {
                isOpenView = true
            }
            Spacer(minLength: 40)
            
            Button("obtenir la taille") {
                Klipfit.shared.requestSize(productID: String, retailerName: String, trackingID: String, customerID: String) { kleepResult in
                    switch kleepResult {
                    case .notSupported:
	                    // Hide CTA
                        print("NotSupported")
                    case .noRecommendationYet:
	                    // Display CTA with neutral label
                        print("NoRecommendationYet")
                    case .recommendationFound(let result):
	                    // Display CTA with size reco
                        print("RecommendationFound: ", result)
                    }
                }
            }
	            Spacer()
        }
        .sheet(isPresented: $isOpenView) {
            KlipFitFindSizeView { result, variantID in 
								// addToCart(variantID)
	          }
        }
    }
}
```

### メソッド 2: `loadView`

このメソッドは CTA がクリックされたときに呼び出されます。各種画面をロードするために使用します。**SDK を統合する開発者は、これらをボトムシートに埋め込む必要があります。**

| パラメータ            | 優先度  | 説明                     |
| ---------------- | ---- | ---------------------- |
| **productID**    | *必須* | 商品 ID                  |
| **retailerName** | *必須* | 小売業者名                  |
| **customerID**   | *任意* | 分析に使用する CRM 識別子        |
| **trackingID**   | *任意* | 外部トラッキングプロバイダーが使用する ID |

**実装例**

```swift theme={null}
struct KlipFitFindSizeView: UIViewControllerRepresentable {
		
		public var onResult: KleepOnResultCompletion

    func makeUIViewController(context: Context) -> KlipftNavigationController {
        guard let viewController =
        KlipftNavigationController.loadView(
                productID: String,
                retailerName: String,
                language: KleepLanguageCode, // .fr .en .es .it .pt .nl 
                trackingID: "",
                customerID: "",
                stocks: [String : Bool]?,
                onResult: onResult
        )
        else {
            fatalError("ViewController not implemented in storyboard")
        }
        viewController.navigationBar.isHidden = true
        return viewController
    }
    func updateUIViewController(_ uiViewController: KlipftNavigationController, context: Context) {
    }
    typealias UIViewControllerType = KlipftNavigationController
}
```

### メソッド 3: `track`

このメソッドはカスタムイベントをトラッキングするために使用します。

| パラメータ     | 優先度  | 説明            |
| --------- | ---- | ------------- |
| eventName | *必須* | トラッキングするイベント名 |
| params    | *任意* | イベントに関連する情報   |

```swift theme={null}
import Klipfit

Klipfit.shared.track(eventName: String, params: [String: Any]? = nil)
```

トラッキングしたい 3 つのイベント:

| eventName               | トリガー           |
| ----------------------- | -------------- |
| `product_viewed`        | PDP 閲覧時        |
| `product_added_to_cart` | 商品がカートに追加されたとき |
| `checkout_completed`    | 支払い後の注文確認時     |

**`product_viewed`**

[パラメータ (CSV)](/images/ios/Untitled%202c68bfd3e84981cabf11f24acd542d96.csv)

**例**

```jsx theme={null}
{
		productId: str
}
```

**`product_added_to_cart`**

[パラメータ (CSV)](/images/ios/Untitled%202c68bfd3e84981858563ca1319b138e8.csv)

**例**

```jsx theme={null}
{
    productId: str,
    variantId: str,
    cart: [
	    {
		    productId: "123ABC456",
		    variantId: "123ABC456-00R",
				sku: "XYZ",
		    size: "S",
		    quantity: 2,
		    price: {
						amount: "50",
				    currencyCode: "EUR"		    
		    }
	    },
	    {
		    productId: "123ABC456",
		    variantId: "123ABC456-00R",
		    sku: "XYZ",
		    size: "S",
		    quantity: 1,
		    price: {
				    amount: "40",
				    currencyCode: "USD"
				}
	    }
	    ...
    ],
}
```

**`checkout_completed`**

[パラメータ (CSV)](/images/ios/Untitled%202c68bfd3e84981e7ad20d59d320148e0.csv)

**例**

```jsx theme={null}
{
    orderId: "000001",
    cart: [
	    {
		    lineItemId: "000001#1",
		    productId: "123ABC456",
		    variantId: "123ABC456-00R",
				sku: "XYZ",
		    size: "S",
		    quantity: 2,
		    price: {
						amount: "50",
				    currencyCode: "EUR"		    
		    }
	    },
	    {
			  lineItemId: "000000#2",
		    productId: "123ABC456",
		    variantId: "123ABC456-00R",
		    sku: "XYZ",
		    size: "S",
		    quantity: 1,
		    price: {
				    amount: "40",
				    currencyCode: "USD"
				}
	    }
	    ...
    ],
}
```
