# iOS SDK

Roboflow Mobile iOS SDK एक बेहतरीन विकल्प है यदि आप एक iOS एप्लिकेशन विकसित कर रहे हैं, जहाँ तेज़ inference के लिए या सुविधाओं, क्षमताओं और उपयोग के मामलों के एक नए सेट (जैसे augmented reality) को सक्षम करने के लिए edge (iPad या iPhone) पर चलने वाला model आवश्यक है।

Custom computer vision models embedded वाले native mobile applications developers को उनके apps को दृष्टि की क्षमता देने की अनुमति देते हैं।

## Task Support

निम्नलिखित task types hosted API द्वारा समर्थित हैं:

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

### CoreML Export Compatibility

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

| Model                 | CoreML Export |
| --------------------- | ------------- |
| RF-DETR               | ✅             |
| YoloLite              | ✅             |
| Classification models | ✅             |

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

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

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

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

## Prototyping

आप इसका उपयोग करके development कर सकते हैं [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 install करते समय आपको `sudo` का उपयोग करना होगा। (हालाँकि यह केवल gem installation की अवधि के लिए एक issue है.)" - [CocoaPods](https://guides.cocoapods.org/using/getting-started.html)

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

यह जांचें कि CocoaPods सफलतापूर्वक installed है या नहीं, यह दर्ज करके `pod --version` अपने Terminal में।

### Roboflow CocoaPod install करना

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

सुनिश्चित करें कि `Podfile` यह specify करता है `platform :ios, '15.4'`

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

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

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

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

![Podfile की successful installation के बाद Terminal](/files/94c165ccd861d6183591a51d792c2f07826779ba)

![Podfile की successful installation के बाद project directory](/files/235f29fa3d79dc0d89359ec138ba56ff1b37d269)

* यदि यह error लौटाता है: "You may have encountered a bug in the Ruby interpreter or extension libraries," तो पहले चलाएँ `brew install cocoapods`और फिर चलाएँ `pod install` और generated `.xcworkspace` file in XCode.
  * यह जांचें कि CocoaPods सफलतापूर्वक installed है या नहीं, यह दर्ज करके `pod --version` अपने Terminal में।

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

नेविगेट करें `.xcworkspace` file in XCode.

![](/files/9fc9d3a8efd2281597d8dee2d184eebaddf8daad)

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

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

#### अपने Project Information को ढूँढना

**Completion Handler Usage:**

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

//model?.detect एक UIImage लेता है और उस पर inference चलाता है
let img = UIImage(named: "example.jpeg") // or 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 का center
y:Float //object y का center
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

The [roboflow-ios-starter](https://github.com/roboflow/roboflow-ios-starter) app roboflow models के साथ realtime iOS app बनाने के लिए एक शानदार starting point है। इसमें camera setup, model loading और processing, तथा 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) installed हैं।

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

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

### Example iOS application - CashCounter

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


---

# Agent Instructions: 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-hi/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.
