Skip to main content

Introduction

The SpreeAITryOn SDK enables users to experiment with outfits virtually by utilizing AI to superimpose garments onto uploaded pictures, thereby creating a visual representation of the outfit on the individual.

Technical Requirements

  • XCode 16.0
  • Swift Package Manager (5.9+)
  • iOS 16.6+

Localization

  • en
  • fr
  • es
  • es-ES
  • it

Prerequisites

  • Google Client Id (provided by SPREEAI)
  • Partner Id (provided by SPREEAI)

Installation

To get started with SpreeAITryOn, follow these steps:

Using Swift Package Manager

Open your project in Xcode. Select File > Swift Packages > Add Package Dependency. Enter the package repository URL and click Next. Choose the version rule and click Finish.

Configurations

First make sure you ask the owner of this library your Google Signin client ID

1. Add your google signin reversed client id in your info plist

<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>YOUR_DOT_REVERSED_IOS_CLIENT_ID</string>
</array>
</dict>
</array>

2. In your AppDelegate make sure the library is properly configured

Using UIKit

import SpreeAITryOn
class AppDelegate: NSObject, UIApplicationDelegate {
...
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {

// Your project setup

SpreeAITryOn.shared.configure(
launchOptions: launchOptions,
googleClientId: YOUR_IOS_GOOGLE_CLIENT_ID,
partnerId: YOUR_SPREEAI_PARTNER_ID
)

return true
}

func application(
_ app: UIApplication,
open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {

let handled = SpreeAITryOn.shared.handleApplicationOpenUrl(url)
if handled {
return true
}

// Your project setup

return false
}

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
// Pass your project supported orientation inside the method in this case the project orientation is "all"
SpreeAITryOn.shared.supportedOrientation(orientation: .all)
}
...
}

Using SwiftUI

AppDelegate.swift

import SpreeAITryOn 

class AppDelegate: NSObject, UIApplicationDelegate {

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {

SpreeAITryOn.shared.configure(
launchOptions: launchOptions,
googleClientId: YOUR_IOS_GOOGLE_CLIENT_ID,
partnerId: YOUR_SPREEAI_PARTNER_ID
)

// Your Project setup

return true
}

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
// Pass your project supported orientation inside the method in this case the project orientation is "all"
SpreeAITryOn.shared.supportedOrientation(orientation: .all)
}
}

YourApp.swift

import SpreeAITryOn 

@main
struct YourApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate

var body: some Scene {
WindowGroup {
ZStack {...}
.onOpenURL { url in
_ = SpreeAITryOn.shared.handleApplicationOpenUrl(url)
...
}
.onContinueUserActivity(NSUserActivityTypeBrowsingWeb, perform: { userActivity in
_ = SpreeAITryOn.shared.application(UIApplication.shared, continue: userActivity, restorationHandler: {_ in })
...
})
}
}
}

Note that SpreeAITryOn.shared.configure() has multiple parameters

3. Adds save photo permission in your info.plist (Optional)

To add the option to save the try-on results in the photo app, you will need to add the NSPhotoLibraryAddUsageDescription permission. Don't forget to do the localization.

Usage

Using SwiftUI

YourView.swift

import SpreeAITryOn
import SwiftUI

struct YourView: View {
@State private var startTryOn: Bool = false

var body: some View {
Button("Open Tryon") {
startTryon.toggle()
}
.fullScreenCover(isPresented: $startTryOn, onDismiss: {
startTryOn = false
}) {
SpreeAITryOn.shared.startTryOnFlow(garmentId: "your garment id") { event in
switch event {
case .cancelled:
// Additionals actions after the try-on was cancelled
case .completed:
// Additionals actions after the try-on is completed
case .redirected(let garmentId):
// Redirect the user within the app to a specific garment if necessary.
case .addToCart(let size, let garmentId):
// Redirect the user within the app to a specific size of a garment if necessary.
}
}
}
}
}

Using UiKit

UIButton(primaryAction: .init { _ in
let viewController: UIViewController = SpreeAITryOn.shared.startTryOnFlow(garmentId: "your garment id") { event in
switch event {
case .cancelled:
// Additionals actions after the try-on was cancelled
case .completed:
// Additionals actions after the try-on is completed
case .redirected(let garmentId):
// Redirect the user within the app to a specific garment if necessary.
case .addToCart(let size, let garmentId):
// Redirect the user within the app to a specific size of a garment if necessary.
}
}
self.navigationController?.present(viewController, animated: true)
})

Branchio

Branchio is used by the SDK. If your app receives a deeplink that opens a garment, the SDK will take care of it. To ensure it works for your app, you will need to ensure that your app is registered in a Branchio account and complete the setup in your Info.plist.

  1. Add your URL scheme:
    <key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string></string>
<key>CFBundleURLSchemes</key>
<array>
<string>YOUR_URL_SCHEME</string>
</array>
</dict>
...
</array>
  1. Add both the live and test keys from Branchio, as well as the domains provided by Branchio:
    <key>branch_key</key>
<dict>
<key>live</key>
<string>YOUR_LIVE_KEY</string>
<key>test</key>
<string>YOUR_TEST_KEY</string>
</dict>
<key>branch_universal_link_domains</key>
<array>
<string>example-alternate.app.link</string>
<string>example.app.link</string>
<string>example.test-app.link</string>
<string>example-alternate.test-app.link</string>
</array>
  1. Make sure you add the entitlements 'Associated Domains' and that they reflect the values you entered in branch_universal_link_domains.