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.

  • Your access key must be setup under Pixelbin > GlamAR console.
  • 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. Select the version you want to use
  4. Click "Add Package"

CocoaPods

  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.

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"
  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

If you prefer not to use a dependency manager:

  1. Download the latest release of GlamAR from the releases page.
  2. Drag and drop GlamAR.framework into your Xcode project.
  3. In your target's "General" settings, add GlamAR under "Frameworks, Libraries, and Embedded Content".

Dependencies

GlamAR depends on Alamofire. If you're using SPM, CocoaPods, or Carthage, this dependency will be automatically managed. If you're installing it manually, make sure to include Alamofire in your project as well.

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:"string")