Now available as Swift package at: https://github.com/Passiolife/Passio-Platform-iOS-SDK-Distribution
Welcome to Passio Platform iOS SDK!
When integrated into your app, the SDK provides you with on-device computer vision for your project.
The SDK creates a video preview layer that passes frames through computer vision network. The predictions for each frame of the video are provided into the preview layer and you can use them to build experiences.
By default the SDK does not record or store any photos or videos. Instead, as the end user hovers over an item with their camera phone, the SDK recognizes and identifies items in real time. This hovering action is transitory and temporary while the end user is pointing the camera at a particular item and is not recorded or stored within the SDK. As a developer, you can configure the SDK to capture images or videos and store them in your app if you need to, but by default the SDK does not capture user data.
In order to use the PassioSDK your app needs to meet the following minimal requirements:
- The SDK will only run on iOS 13 or newer.
- Passio SDK can only be used on a device and will not run on a simulator
- The SDK requires access to iPhone's camera
- Login into the platform https://platform.passiolife.com/
- Under Project Status click on the "Continue" button on right of your project row.
- Under SDK Packaging select the latest Version (or any other desired version) and click on the "Details"
- Copy the Project ID at the bottom of the page. You will use it to configure the SDK to run your models.
- Download the iOS Package to your Mac and unzip it.
- Drag and drop the files to your Xcode Project Navigator
A fast and easy way to get started with the SDK is to test it inside of PlatformSDKDemoApp included in this package. Here are the steps:
- Open the project in Xcode:
- Get the key from the platform. Click on your profile "My Organization" https://platform.passiolife.com/organization . The Mobile SDK Key should be copied from here above
- Drag ad Drop the models as described below.
- In the
VideoViewController
, replace both the key and the projetID replace. You will have to do the same when you install the SDK your App too.
let key = "Your_SDK_Key"
let projectID = "Your_projectID"
- Connect your iPhone and run
- Modify the app bundle from "com.PassioDemoApp.demo" to "com.yourcompany...."
- Run the demo app on your iPhone.
- Open your Xcode project.
- Go to File > Swift Packages > Add Package Dependency.
- In the "Add Package Dependency" dialog box, paste the URL: https://github.com/Passiolife/Passio-Platform-iOS-SDK-Distribution
- Click "Next". Xcode will validate the package and its dependencies.
- In the next dialog box, you'll be asked to specify the version or branch you want to use. You can choose main for the latest version or specify a specific version or branch.
- After you've made your selection, click "Next".
- You'll then be prompted to select the targets in your project that should include the package. Check the boxes for the targets you want to include.
- Click "Finish" to add the package to your project.
- Xcode will download and add the PassioPlatformSDK to your project. You can now import and start using the PassioPlatformSDK.
- If opening from Xcode, right click and select 'open as source code'
- To allow camera usage add:
`<key>NSCameraUsageDescription</key><string>For real-time recognition</string>`.
- To allow the data collection API (please contact support@passiolife.com for more information) add:
`<key>NSMicrophoneUsageDescription</key>
<string>To record videos with sound for classification</string>`
`<key>NSPhotoLibraryAddUsageDescription</key>
<string>To select images and videos for classification</string>`
- At the top of your view controller import the PlatformSDK and AVFoundation
import AVFoundation
import PassioPlatformSDK
- Add the following properties to your view controller.
let passioSDK = PassioPlatformAISDK.shared
var videoLayer: AVCaptureVideoPreviewLayer?
- In viewDidLoad configure the SDK with the Key you have received form Passio.
override func viewDidLoad() {
super.viewDidLoad()
#error("Replace the SDK Key and the project ID. Description how to find then above.")
let key = "Your_SDK_Key"
let projectID = "Your_projectID"
var passioConfig = PassioConfiguration(key: key)
passioConfig.projectID = projectID
passioSDK.configure(passioConfiguration: passioConfig) { status in
print( "SDK status = \(status)")
}
passioSDK.statusDelegate = self
}
- You will receive the PassioStatus back from the SDK.
public struct PassioStatus {
public internal(set) var mode: PassioSDK.PassioMode { get }
public internal(set) var missingFiles: [PassioSDK.FileName]? { get }
public internal(set) var debugMessage: String? { get }
public internal(set) var activeModels: Int? { get }
}
public enum PassioMode {
case notReady
case isBeingConfigured
case isDownloadingModels
case isReadyForDetection
case failedToConfigure
}
- In
viewWillAppear
request authorization to use the camera and start the recognition:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if AVCaptureDevice.authorizationStatus(for: .video) == .authorized { // already authorized
setupVideoLayer()
} else {
AVCaptureDevice.requestAccess(for: .video) { (granted) in
if granted { // access to video granted
DispatchQueue.main.async {
self.setupVideoLayer()
}
} else {
print("The user didn't grant access to use camera")
}
}
}
}
- Add the method
setupVideoLayer
:
func setupVideoLayer() {
guard videoLayer == nil else { return }
if let vLayer = passioSDK.getPreviewLayer() {
self.videoLayer = vLayer
videoLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
videoLayer?.frame = view.frame
view.layer.insertSublayer(vLayer, at: 0)
}
if passioSDK.status.mode == .isReadyForDetection {
startDetection()
}
}
- Add the method
start and stop Detection
func startDetection() {
passioSDK.startDetection(detectionDelegate: self) { isReady in
print("startCustomObjectDetection started \(isReady)" )
}
}
func stopDetection() {
passioSDK.stopDetection()
}
- Stop Detection in
viewWillDisappear
:
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
passioSDK.stopDetection()
videoLayer?.removeFromSuperlayer()
videoLayer = nil
}
- Implement the delegate
DetectionDelegate
:
extension VideoViewController: DetectionDelegate {
func detectionResult(candidates: [DetectionCandidate]?,
image: UIImage?) {
if let first = candidates?.first {
// display first or al candidates
}
}
}
10 ) Implement the PassioStatusDelegate
:
extension VideoViewController: PassioStatusDelegate {
func passioStatusChanged(status: PassioStatus) {
if status.mode == .isReadyForDetection {
DispatchQueue.main.async {
self.startDetection()
}
}
}
func passioProcessing(filesLeft: Int) {
DispatchQueue.main.async {
}
}
func completedDownloadingAllFiles(filesLocalURLs: [FileLocalURL]) {
DispatchQueue.main.async {
}
}
func completedDownloadingFile(fileLocalURL: FileLocalURL, filesLeft: Int) {
DispatchQueue.main.async {
}
}
func downloadingError(message: String) {
print("downloadError ---- =\(message)")
DispatchQueue.main.async {
}
}
}
Copyright 2022 Passio Inc