Setup guide for iOS

This page shows you how to set up your development environment to use MediaPipe Tasks in your iOS applications.

Supported devices and platforms

To create iOS applications with MediaPipe Tasks, your development environment requires the following:

  • macOS Mojave 10.14.3 or greater.

  • Xcode 14.1 or greater.

  • iOS device or simulator with at least iOS 15.0. Alternatively, an iOS simulator can handle applications that don't require the device camera.

Developer environment setup

Before running a MediaPipe task on an iOS application, you must either have an existing Xcode project or create a new one on your local machine.

MediaPipe Tasks can be installed using Swift Package Manager (SPM) in Xcode.

Example code setup

The MediaPipe Examples repository contains example iOS applications for MediaPipe tasks.

You can create a project from the example code, build the project, and run the task. The following steps builds the Text Classifier task.

To import and build the example code project:

  1. Open the terminal, clone the MediaPipe Examples repository, and navigate to the directory containing TextClassifier.xcodeproj.

    git clone https://github.com/google-ai-edge/mediapipe-samples
    cd mediapipe-samples/examples/text_classification/ios
    
  2. Open the TextClassifier.xcodeproj file in Xcode. Xcode will automatically resolve and download the required Swift package dependencies.

  3. Select the TextClassifier scheme and choose a physical iOS device or simulator from the toolbar of your project window. When using a physical iOS device, ensure that it is connected to your Mac.

  4. Click the Run button in your project's toolbar.

For more instructions on running an app on Xcode, refer to Building and running an app.

MediaPipe Tasks dependencies

MediaPipe Tasks provides prebuilt libraries for vision, text, and audio. The model file (.task or .tflite) must be located in the bundle of the iOS application that uses the model.

Adding dependencies in Xcode

To add the MediaPipe Tasks Swift package to your Xcode project:

  1. With your project open in Xcode, select File > Add Package Dependencies....

  2. In the search field in the upper right, enter the repository URL:

    https://github.com/google-ai-edge/mediapipe
    
  3. Select the mediapipe package and choose your desired dependency rule (for example, Up to Next Major Version or the master branch).

  4. Click Add Package.

  5. In the package products dialog, select the libraries required for your application and add them to your application target:

    • Vision tasks: MediaPipeTasksVision
    • Text tasks: MediaPipeTasksText
    • Audio tasks: MediaPipeTasksAudio

Adding dependencies in Package.swift

If you are developing a Swift package, add the MediaPipe package to your Package.swift dependencies:

dependencies: [
    .package(
        url: "https://github.com/google-ai-edge/mediapipe",
        branch: "master"
    ),
],
targets: [
    .target(
        name: "MyAppTarget",
        dependencies: [
            .product(name: "MediaPipeTasksVision", package: "mediapipe"),
        ]
    ),
]

BaseOptions configuration

The BaseOptions allow for general configuration of MediaPipe Task APIs.

Option name Description Accepted values
modelAssetPath The model path to a model file in the iOS application bundle. Path as a string.

Hardware acceleration

On iOS, MediaPipe Tasks only supports running models on standard CPU processors.

Troubleshooting

For help with technical questions related to MediaPipe, visit the discussion group or Stack Overflow for support from the community. To report bugs or make feature requests, file an issue on GitHub.

For help setting up your iOS development environment, visit the Apple Developer Documentation.