Skip to main content

iOS Package Setup

As you follow this tutorial, we recommend using our demo project reference to assist you in integrating the SDK into your project.

Prerequisites​

To follow along you should have basic knowledge of creating ios apps with Xcode and it's ecosystem. In this tutorial we are going to use:

Don't worry if you don't have a lot of experience with these (or any experience at all). It is pretty straightforward to use and we will explain everything along.

Install Xcode and its relevant simulators and versions to use and run project, if you haven't already.

  • Create your access key in Fynd Console → your organization → GlamAR → your product account → Settings → Tokens.
  • Under tab GlamAR > Skin Analysis, should have atleast one app with its appId

Visit Getting Started Page if access key or SKU has not been created

Installation​

You can integrate GlamAR into your project using one of the following dependency managers:

Swift Package Manager (SPM)​

  1. In Xcode, select "File" → "Add Packages..."
  2. Enter the following URL in the search bar: https://github.com/pixelbin-io/glamar-swift.git
  3. Set the dependency rule to Branch and enter main.
  4. Click "Add Package"

CocoaPods​

The iOS SDK is available as GlamAR on CocoaPods. Use the unversioned declaration below to install the latest compatible published release.

  1. If you haven't already, install CocoaPods:

    gem install cocoapods
  2. In your project directory, create a Podfile if you don't have one:

    pod init
  3. Add the following line to your Podfile:

    pod 'GlamAR'
  4. Run the following command:

    pod install
  5. Open the .xcworkspace file to work with your project in Xcode.

If GlamAR is already installed, update it to the latest compatible release:

pod update GlamAR

Carthage​

  1. If you haven't already, install Carthage:

    brew install carthage
  2. In your project directory, create a Cartfile if you don't have one:

    touch Cartfile
  3. Add the following line to your Cartfile:

    github "pixelbin-io/glamar-swift" "main"
  4. Run the following command:

    carthage update --use-xcframeworks
  5. In your target's "General" settings, add the built GlamAR.xcframework from Carthage/Build to the "Frameworks, Libraries, and Embedded Content" section.

Manual Installation​

To work with the latest SDK source locally, clone the main branch:

git clone --branch main --single-branch https://github.com/pixelbin-io/glamar-swift.git

In your app's Xcode project, choose File → Add Package Dependencies → Add Local, select the cloned glamar-swift folder, and add the GlamAR product to your app target.

Dependencies​

GlamAR depends on Alamofire. SPM (including the local-package setup above), CocoaPods, and Carthage manage this dependency automatically.

After installation, import GlamAR in your Swift files:

import GlamAR

Now you're ready to use GlamAR in your project!

Initialization​

To use GlamAR in your iOS application, you need to initialize it with your access key. The initialization should be done when your app starts, typically in your AppDelegate or SceneDelegate.

import GlamAR

// In your AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Initialize GlamAR with all available options
// Optional: Can also pass a pre-configured WKWebView as webView
let overrides = GlamAROverrides(
category: "skinanalysis",
configuration: Configuration(skinAnalysis: SkinAnalysisConfig(appId: "Your_skin-app-id"))
)
GlamAr.initialize(
accessKey: "YOUR_ACCESS_KEY",
debug: true, // Use debug environment (true) or production (false)
bundleIdentifier: String = Bundle.main.bundleIdentifier ?? "", // Used for parent domain reference
overrides: overrides)
return true
}

Configuration Options​

  • accessKey: Your unique access key for the GlamAR service (Required)
  • debug: Boolean flag to switch between debug and production environments
    • true: Uses debug/staging environment (default)
    • false: Uses production environment
  • bundleIdentifier: Parent domain reference (Required)
  • overrides: Category configurations (Required)
  • webView : Pre-configured WKWebView (Optional)

Getting GlamAR Instance​

After initialization, you can get the GlamAR instance using:

do {
let glamAr = try GlamAr.getInstance()
// Use glamAr instance
} catch GlamArError.notInitialized {
print("GlamAR not initialized")
}

GlamArWebViewManager​

The GlamArWebViewManager is the main component for displaying AR content. We use Webkit to display and communicate with our SDK. Make sure to add it inside your Storyboard or create it dynamically using SwiftUI. We use Storyboard approch

Image

import UIKit
import GlamAR
import WebKit

class ViewController: UIViewController {
// Refrence to webview for using in storyboard
@IBOutlet weak var glamARWebView: WKWebView!
// Create a webview
if let webview = GlamArWebViewManager.shared.getPreparedWebView() {
glamARWebView.addSubview(glamARWebView)
}
}

Basic Functions​

addEventListener​

Event listeners are essential soon after initialization is called to start listening to GlamAR SDK callback events.

GlamAr.addEventListener(event: "loaded") { (callbackValue) in
print("loaded: \(callbackValue ?? "")")
}

GlamAr.addEventListener(event: "sku-applied") { (callbackValue) in
print("sku-applied: \(callbackValue ?? "")")
}

skinAnalysis​

Once called will start skin analysis flow of scanning and showing result

GlamAr.skinAnalysis(options: "start")