Mobile iOS (On Device)
Deploy your trained Roboflow model in your iOS app

When should you use edge deployment?

Our Hosted API is suitable for most use-cases; the hosted API uses battle-tested infrastructure and seamlessly autoscales up and down to handle even the most intense use-cases.
But, because it is hosted remotely, there are some scenarios where it's not ideal: notably, in situations where bandwidth is constrained or where production data cannot extend beyond your local network or corporate firewall or where you need realtime inference speeds on the edge.
In those cases, an on-premise deployment is needed. And the Roboflow Mobile iOS SDK is a great option if you are developing an iOS application.

Supported Hardware and Software

All iOS devices support on-device inference, but those older than the iPhone 8 (A11 Bionic Processor) will fall back to the less energy efficient gpu engine.
Roboflow requires a minimum iOS version of 15.4.

Prototyping

You can develop against the Roboflow Hosted Inference API. It uses the same trained models as on-device inference.

Installation

Currently the Mobile iOS deploy is in beta and available to a whitelist of Roboflow developers.

Installing the Roboflow CocoaPod

First, run pod init in your project directory.
Make sure the Podfile specifies the platform :ios, '15.4'
Next, add pod 'Roboflow' to your Podfile.
Lastly, run pod install and open the generated .xcworkspace file in xcode.

Using Roboflow in Swift

First import Roboflow with import Roboflow.
Next create an instance of the Roboflow API with let rf = Roboflow(apiKey: API_KEY).
Completion Handler Usage:
1
import Roboflow
2
...
3
//initalize with your API Key
4
let rf = RoboflowMobile(apiKey: API_KEY)
5
var model: RFObjectDetectionModel?
6
...
7
8
//model is your model's project name
9
rf.load(model: "YOUR-MODEL-ID", modelVersion: YOUR-MODEL-VERSION-#) { [self] model, error, modelName, modelType in
10
if error != nil {
11
print(error?.localizedDescription as Any)
12
} else {
13
model?.configure(threshold: threshold, overlap: overlap, maxObjects: maxObjects)
14
self.model = model
15
}
16
17
}
18
...
19
20
//model?.detect takes a UIImage and runs inference on it
21
let img = UIImage(named: "example.jpeg")
22
model?.detect(image: img!) { predictions, error in
23
if error != nil {
24
print(error)
25
} else {
26
print(predictions)
27
}
28
}
Copied!
Asynchronous Usage:
To use asynchronously, you must be invoking your Roboflow model within an asynchronous block.
1
import Roboflow
2
...
3
//initalize with your API Key
4
let rf = RoboflowMobile(apiKey: API_KEY)
5
...
6
7
//model is your model's project name
8
let (model, loadingError, modelName, modelType) = await rf.load(model: "YOUR-MODEL-ID", modelVersion: YOUR-MODEL-VERSION-#)
9
model!.configure(threshold: threshold, overlap: overlap, maxObjects: maxObjects)
10
...
11
12
//model?.detect takes a UIImage and runs inference on it
13
let img = UIImage(named: "example.jpeg")
14
let (predictions, predictionError) = await model!.detect(image: img!)
15
print(predictions)
Copied!
Predictions Format:
1
x:Float //center of object x
2
y:Float //center of object y
3
width:Float
4
height:Float
5
className:String
6
confidence:Float
7
color:UIColor
8
box:CGRect
Copied!
CGRect

React Native Expo App Example

We also provide an example of integrating this SDK into an expo app with React Native here. You may find this useful when considering the construction of your own downstream application.