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)
- In Xcode, select "File" → "Add Packages..."
- Enter the following URL in the search bar:
https://github.com/pixelbin-io/glamar-swift.git - Select the version you want to use
- Click "Add Package"
CocoaPods
-
If you haven't already, install CocoaPods:
gem install cocoapods -
In your project directory, create a
Podfileif you don't have one:pod init -
Add the following line to your Podfile:
pod 'GlamAR' -
Run the following command:
pod install -
Open the
.xcworkspacefile to work with your project in Xcode.
Carthage
-
If you haven't already, install Carthage:
brew install carthage -
In your project directory, create a
Cartfileif you don't have one:touch Cartfile -
Add the following line to your Cartfile:
github "pixelbin-io/glamar-swift" -
Run the following command:
carthage update --use-xcframeworks -
In your target's "General" settings, add the built
GlamAR.xcframeworkfromCarthage/Buildto the "Frameworks, Libraries, and Embedded Content" section.
Manual Installation
If you prefer not to use a dependency manager:
- Download the latest release of GlamAR from the releases page.
- Drag and drop
GlamAR.frameworkinto your Xcode project. - 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 environmentstrue: Uses debug/staging environment (default)false: Uses production environment
bundleIdentifier: Parent domain reference (Required)overrides: Category configurations (Required)webView: Pre-configuredWKWebView(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
![]()
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")