# iOS SDK

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

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

## Task Support

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

| Task Type             | iOS SDK Deployment द्वारा Supported |
| --------------------- | ----------------------------------- |
| 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 करें

### Supported Hardware and Software

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

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

## Prototyping

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

## Installation

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

"CocoaPods Ruby के साथ built है और यह macOS पर उपलब्ध default Ruby के साथ installable होगा। आप एक 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)

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

Terminal में `pod --version` दर्ज करके जाँचें कि CocoaPods सफलतापूर्वक install हो गया है।

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

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

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

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

यदि आपके पास XCode Command Line Tools installed नहीं हैं, तो चलाएँ `xcode-select --install` दर्ज करके जाँचें कि CocoaPods सफलतापूर्वक install हो गया है।

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

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

![में खोलें, Podfile की सफल installation के बाद Terminal में](https://2698615118-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M6S9nPJhEX9FYH6clfW%2Fuploads%2Fgit-blob-742fddf172d5eea914ea63a42170583cbe748443%2Fimage.png?alt=media)

![Podfile की सफल installation के बाद project directory](https://2698615118-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M6S9nPJhEX9FYH6clfW%2Fuploads%2Fgit-blob-85737dbd1b9fcb80ea6674633012e85c908f5c30%2Fimage.png?alt=media)

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

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

पर जाएँ `.xcworkspace` file in XCode.

![](https://2698615118-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M6S9nPJhEX9FYH6clfW%2Fuploads%2Fgit-blob-845222e3655098babfff65dff3575a9886c12c24%2Fimage.png?alt=media)

इसके बाद, जोड़कर 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 का पता लगाना](https://docs.roboflow.com/roboflow/roboflow-hi/deploy/sdks/broken-reference)

**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 या .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

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

### React Native Expo App Example

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

सुनिश्चित करें कि आपके पास दोनों [Expo](https://docs.expo.dev/) और [CocoaPods](https://cocoapods.org/) installed हैं।

* `expo-cli` निम्न Node.js versions को support करता है: `>=12.13.0 <15.0.0` (Maintenance LTS) और `>=16.0.0 <17.0.0` (Active LTS)
* yarn package Node.js के लिए 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, और अधिक को visualise करने के examples दिखाई देंगे।
