> 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-hi/deploy/sdks/ios-sdk.md).

# iOS SDK

Roboflow Mobile iOS SDK एक बेहतरीन विकल्प है यदि आप ऐसा iOS application विकसित कर रहे हैं जहाँ तेज़ inference के लिए या features, capabilities, और use cases (जैसे augmented reality) के नए suite को unlock करने के लिए edge (iPad या iPhone) पर चलने वाला model आवश्यक है।

Custom computer vision models embedded वाले native mobile applications developers को अपने apps को देखने की क्षमता प्रदान करने देते हैं।

## कार्य समर्थन

निम्नलिखित task types iOS SDK Deployment द्वारा समर्थित हैं:

| कार्य प्रकार          | iOS SDK Deployment द्वारा समर्थित |
| --------------------- | --------------------------------- |
| Object Detection      | ✅                                 |
| Classification        |                                   |
| Instance Segmentation | ✅ (iOS 18 या उससे उच्चतर)         |
| Semantic Segmentation |                                   |

### CoreML Export Compatibility

निम्नलिखित model architectures CoreML (`.mlpackage`) on-device deployment के लिए export का समर्थन करती हैं:

| मॉडल                  | CoreML Export |
| --------------------- | ------------- |
| RF-DETR               | ✅             |
| YoloLite              | ✅             |
| Classification models | ✅             |

## एक iOS Device पर Model Deploy करें

### समर्थित Hardware और Software

सभी iOS devices on-device inference का समर्थन करते हैं, लेकिन iPhone 8 (A11 Bionic Processor) से पुराने devices कम energy-efficient gpu engine पर fall back करेंगे।

Roboflow के लिए न्यूनतम iOS version 15.4 आवश्यक है (instance segmentation models के लिए 18.0)।

## Prototyping

आप इसके विरुद्ध develop कर सकते हैं [Roboflow Serverless Hosted API](https://docs.roboflow.com/deploy/serverless)। यह on-device inference के समान trained models का उपयोग करता है।

## Installation

* Install [CocoaPods](https://guides.cocoapods.org/using/getting-started.html) | [Troubleshooting Guide](https://guides.cocoapods.org/using/troubleshooting#installing-cocoapods)

"CocoaPods Ruby के साथ बनाया गया है और macOS पर उपलब्ध default Ruby के साथ install किया जा सकेगा। आप एक Ruby Version manager का उपयोग कर सकते हैं, हालांकि हम recommend करते हैं कि आप macOS पर उपलब्ध standard Ruby का उपयोग करें जब तक आपको पता न हो कि आप क्या कर रहे हैं। Default Ruby install का उपयोग करने पर gems इंस्टॉल करते समय आपको sudo का उपयोग करना होगा। (हालाँकि, यह केवल gem installation की अवधि के लिए एक समस्या है।)" - `sudo` का उपयोग करना होगा जब gems इंस्टॉल कर रहे हों। (हालाँकि, यह केवल gem installation की अवधि के लिए ही एक समस्या है।)" - [CocoaPods](https://guides.cocoapods.org/using/getting-started.html)

"Sudo-less" installation एक विकल्प है, यदि आप इस प्रक्रिया के लिए RubyGems को admin privileges नहीं देना चाहते। हालांकि, ध्यान दें कि `sudo` installation अधिक सामान्य है।

जांचें कि CocoaPods सफलतापूर्वक इंस्टॉल हुआ है, इसके लिए दर्ज करें `pod --version` अपने Terminal में।

### Roboflow CocoaPod इंस्टॉल करना

सबसे पहले, चलाएँ `pod init` अपने project directory में।

सुनिश्चित करें कि `Podfile` निम्नलिखित निर्दिष्ट करता है `platform :ios, '15.4'`

इसके बाद, जोड़ें `pod 'Roboflow'` अपने `Podfile`.

यदि आपके पास XCode Command Line Tools इंस्टॉल नहीं हैं, तो चलाएँ `xcode-select --install` अपने Terminal में।

यह लौटाएगा: `xcode-select: error: command line tools पहले से इंस्टॉल हैं, updates इंस्टॉल करने के लिए "Software Update" का उपयोग करें` यदि Command Line Tools आपके system पर पहले से मौजूद हैं।

अंत में, चलाएँ `pod install` और generated `.xcworkspace` फ़ाइल को [XCode](https://developer.apple.com/xcode/).

![Podfile के सफल installation के बाद Terminal](/files/94c165ccd861d6183591a51d792c2f07826779ba)

![Podfile के सफल installation के बाद project directory](/files/235f29fa3d79dc0d89359ec138ba56ff1b37d269)

* यदि यह error लौटाता है: "आपको Ruby interpreter या extension libraries में एक bug मिला हो सकता है," तो पहले चलाएँ `brew install cocoapods`, और फिर चलाएँ `pod install` और generated `.xcworkspace` फ़ाइल को XCode में।
  * जांचें कि CocoaPods सफलतापूर्वक इंस्टॉल हुआ है, इसके लिए दर्ज करें `pod --version` अपने Terminal में।

### Swift में Roboflow का उपयोग

पर जाएँ `.xcworkspace` फ़ाइल को XCode में।

![](/files/9fc9d3a8efd2281597d8dee2d184eebaddf8daad)

इसके बाद, जोड़कर Roboflow import करें `import Roboflow`. को `.xcworkspace` फ़ाइल में।

फिर, के साथ Roboflow API का एक instance बनाएँ `let rf = Roboflow(apiKey: "API_KEY")`. के लिए `modelVersion`, प्रतिस्थापित करें `YOUR-MODEL-VERSION-#` अपने model के version number के integer value से।

#### अपने Project Information का पता लगाना

**Completion Handler का उपयोग:**

```swift
import Roboflow
...
//अपने API Key के साथ initialize करें
let rf = RoboflowMobile(apiKey: "API_KEY")
var model: RFModel?
...

//model आपके model का project name है
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 या .balanced या .quality, // instance seg
                            maxNumberPoints: mask processing points की अधिकतम संख्या) // instance seg
        self.model = model
    }
    
}
...

//model?.detect एक UIImage लेता है और उस पर inference चलाता है
let img = UIImage(named: "example.jpeg") // या CVPixelBuffer
model?.detect(image: img!) { predictions, error in
    if error != nil {
        print(error)
    } else {
        print(predictions)
    }
}
```

**Asynchronous Usage:**

Asynchronously उपयोग करने के लिए, आपको अपने Roboflow model को एक asynchronous block के भीतर invoke करना होगा।

```swift
import Roboflow
...
//अपने API Key के साथ initialize करें
let rf = RoboflowMobile(apiKey: "API_KEY")
...

//model आपके model का project name है
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 लेता है और उस पर inference चलाता है
let img = UIImage(named: "example.jpeg")
let (predictions, predictionError) = await model!.detect(image: img!)
print(predictions)
```

**Predictions Format:**

```
x:Float // object का केंद्र x
y:Float // object का केंद्र 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)

### Native Swift Example

यह [roboflow-ios-starter](https://github.com/roboflow/roboflow-ios-starter) app roboflow models के साथ एक realtime iOS app बनाने के लिए एक शानदार starting point है। इसमें camera setup, model loading और process, तथा object-detection और instance segmentation models दोनों के लिए output drawing code शामिल है।

### React Native Expo App Example

हम यहाँ React Native के साथ इस SDK को एक expo app में integrate करने का example भी प्रदान करते हैं। अपने downstream application के निर्माण पर विचार करते समय आपको यह उपयोगी लग सकता है।

सुनिश्चित करें कि आपके पास दोनों [Expo](https://docs.expo.dev/) और [CocoaPods](https://guides.cocoapods.org/using/getting-started.html) इंस्टॉल हैं।

* `expo-cli` निम्नलिखित Node.js versions का समर्थन करता है: `>=12.13.0 <15.0.0` (Maintenance LTS) और `>=16.0.0 <17.0.0` (Active LTS)
* Node.js (`npm install -g yarn`)

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

### उदाहरण iOS application - CashCounter

Download [CashCounter](https://apps.apple.com/app/roboflow-cash-counter/id1633812788), हमारा example iOS app जो US coins और bills गिनता है, यह एक example है कि आप iPhone पर computer vision model कैसे deploy कर सकते हैं। आपको bounding boxes, FPS, object counting, image upload, और अधिक को visualize करने के examples दिखाई देंगे।
