Skip to main content

iOS Framework API References

Initialization Method​

GlamAr.initialize(
accessKey: String, // Required - Pass your unique access key for the GlamAR service
debug: Bool? = false, // false by default
bundleIdentifier: String? = Bundle.main.bundleIdentifier, // Bundle.main.bundleIdentifier by default
overrides: GlamAROverrides? = nil,
webView:WKWebView? = nil) //
ParametersTypeDescriptionOptions
accessKeystringYour unique access key for the GlamAR serviceRequired
debugbooleanA flag to switch between debug and production environments

true: Uses debug/staging environment
false: Uses production environment Default - false

bundleIdentifierstringIdentifier is used for parent domain white listing

Default - Bundle.main.bundleIdentifier

overridesGlamAROverrides

Category configurations. Check GlamAROverrides inside GlamAR package

Default - nil

webViewWKWebViewPass a pre-configured WKWebView

Default - nil

GlamAROverrides Structure​

meta: [String: Any]?​

Contains initialization metadata. Use preloadMLModels to download ML models during SDK initialization. AR Try-On supports face, hair, hand, and light.

let overrides = GlamAROverrides(
category: "sunglasses",
meta: [
"preloadMLModels": ["face", "hair", "hand", "light"]
]
)

GlamAr.initialize(
accessKey: "YOUR_ACCESS_KEY",
overrides: overrides
)

Post-Initialization Methods​

applyBySku​

GlamAr.applyBySku(skuId: String);

Load a virtual try-on using applyBySku method and passing the relevant SKU Id.
Return Value: None

ParametersTypeDescription
SKU Idstring A SKU ID.

applyByCategory​

Loads the product catalog for a supported category. Pass optional catalog settings to filter the products by storefront.

GlamAr.applyByCategory(category: "eyewear")
GlamAr.applyByCategory(
category: "eyewear",
options: ApplyCatalogOptions(storeFront: "store_a")
)
ParameterTypeDescription
categoryStringRequired. A supported category, such as eyewear. See supported categories and subcategories.
optionsApplyCatalogOptions?Optional catalog settings.
options.storeFrontStringOptional storefront filter. Use the exact key storeFront and a nonblank storefront value.

Omit options to load the catalog without a storefront filter. An explicitly empty or whitespace-only storeFront is rejected. Returns no value.

applyBySubCategory​

Loads the product catalog for a supported subcategory. Pass optional catalog settings to filter the products by storefront.

GlamAr.applyBySubCategory(subCategory: "sunglasses")
GlamAr.applyBySubCategory(
subCategory: "sunglasses",
options: ApplyCatalogOptions(storeFront: "store_a")
)
ParameterTypeDescription
subCategoryStringRequired. A supported subcategory, such as sunglasses. See supported categories and subcategories.
optionsApplyCatalogOptions?Optional catalog settings.
options.storeFrontStringOptional storefront filter. Use the exact key storeFront and a nonblank storefront value.

Omit options to load the catalog without a storefront filter. An explicitly empty or whitespace-only storeFront is rejected. Returns no value.

applyMultipleConfigData​

GlamAr.applyMultipleConfigData(skuConfigArray: Any);

Display multiple SKU types at once. The input should be an array of sku configs. Each item can be of diffrent subcategory eg: sunglasses, caps, earrings, etc.
Return Value: None

ParametersTypeDescription
skuConfigArrayobjectAn Array of SKU Configs

Following is an example of above skuConfigArray for applyMultipleConfigData.

struct EffectAsset3D: Codable {
let id: String
let url: String
}

struct EnvSettings: Codable {
let useDefaultEnvironment: Bool
}

struct ArEffect: Codable {
let envSettings: EnvSettings
let effectAssets3D: [EffectAsset3D]
}

struct SkuConfig: Codable {
let category: String
let subCategory: String
let status: String
let productName: String?
let productImage: String?
let arEffect: ArEffect
}

// MARK: - Example data

let data: [SkuConfig] = [
SkuConfig(
category: "eyewear",
subCategory: "eyeglasses",
status: "PUBLISHED",
arEffect: ArEffect(
envSettings: EnvSettings(useDefaultEnvironment: true),
effectAssets3D: [
EffectAsset3D(id: "full", url: "VALID-ASSET-URL") // Valid Asset url
]
),
),
SkuConfig(
category: "accessories",
subCategory: "caps",
status: "PUBLISHED",
productName: "Test cap",
productImage: "VALID-ASSET-IMAGE-URL", // Valid image url
arEffect: ArEffect(
envSettings: EnvSettings(useDefaultEnvironment: true),
effectAssets3D: [
EffectAsset3D(id: "full", url: "VALID-ASSET-URL") // Valid Asset url
]
),
)
]

GlamAr.applyMultipleConfigData(data);

Users will see separate tabs for each category type in the SDK UI.

addEventListener​

GlamAr.addEventListener(event: String, callback: @escaping (Any?) -> Void);

Adds the listener to the given event name.
Return Value: None

ParametersTypeDescription
eventNamestring

A Name of specific event or "*" To listen to the all the events.

handlerFunctionfunction Your handler function that will listen to callback.

removeEventListener​

GlamAr.removeEventListener(event:String);

Removes the given listener for the event name.
Return Value: None

ParametersTypeDescription
eventNamestring

A Name of specific event or "*" To remove all the events.

isLoaded​

GlamAr.isLoaded();

Returns the status of module loading.
Return Bool: true if loaded, otherwise false

ParametersDescription

None

No parameters required.

reset​

Removes all applied effects when called without arguments. In multi-try-on, pass a subcategory string or an options object/map to remove selected effects while keeping the others.

GlamAr.reset()
GlamAr.reset("blush")
GlamAr.reset(["subCategory": "blush"])
GlamAr.reset(["skuIds": ["sku-1", "sku-2"]])
ParameterTypeDescription
valueString or [String: Any]Optional. A subcategory string is shorthand for the subCategory option.
subCategoryStringSubcategory to clear, such as blush.
skuIds[String]IDs of applied SKUs to remove. Pass individual IDs as list entries.

If both filters are supplied, a nonempty skuIds list takes precedence over subCategory. Omitting the argument, passing an empty string, or passing options with no nonempty filter clears all effects.

Returns no value.

configChange​

Updates an adjustment for the active try-on. Availability depends on the current product and experience. skuId and subCategory select the makeup opacity target during multi-try-on; they do not scope finger, position, or scale adjustments.

Use configChange(type:value:skuId:subCategory:). Only type is required; preserve the Swift argument labels.

GlamAr.configChange(type: "opacity", value: 0.5)
GlamAr.configChange(type: "fingers", value: 2)
GlamAr.configChange(type: "horizontal", value: 0)
GlamAr.configChange(type: "vertical", value: 0)

// Target makeup opacity during multi-try-on.
GlamAr.configChange(type: "opacity", value: 0.5, skuId: "sku-1")
GlamAr.configChange(type: "opacity", value: 0.5, subCategory: "lipstick")

// Select the makeup opacity target without changing its value.
GlamAr.configChange(type: "opacity", subCategory: "lipstick")
ParameterTypeDescription
typeStringRequired. opacity (also accepted as intensity), fingers, horizontal, vertical, or scale.
valueDouble?Numeric adjustment. Supply a value when changing an adjustment. For opacity/intensity, omitting the value selects the target without changing its opacity.
skuIdStringOptional applied makeup SKU ID to target.
subCategoryStringOptional applied makeup subcategory to target, such as lipstick or blush.

Pass one target selector per call. With neither selector, the SDK uses its active makeup target. Returns no value.

setViewportMirrored​

GlamAr.setViewportMirrored(state: state)

Enables or disables mirrored viewport rendering for AR Try-On.
Return Value: None

GlamAr.setViewportMirrored(state: true) // Enable mirrored viewport
GlamAr.setViewportMirrored(state: false) // Disable mirrored viewport
ParametersTypeDescriptionOptions
stateBoolControls whether the AR viewport should render in mirrored mode.

true: enable mirror mode
false: disable mirror mode

close​

GlamAr.close();

Closes canvas and returns to the main widget page.
Return Value: None

ParametersDescription

None

No parameters required.

snapshot​

GlamAr.snapshot();

Takes a snapshot of the current result window. Result of the screen can be get from photo-loaded event in base64 formate.
Return Value: none

ParametersDescription

None

No parameters required.

comparison​

GlamAr.comparison(state: String, skus: Any?);

Toggles comparison mode in AR widget.
Return Value: None

Pass a state (i.e, open or close) to toggle between UI and with it 2 SKU ids or Skuconfig of same subcategory say sunglasses or necklace. Diffrent subcategory comparision is not supoorted. The first sku will be shown on the left side and the other one on the right side.

ParametersTypeDescriptionOptions
statestringState to show or hide the UI respectively"open" "close"
skusstring[] | object[]Provide 2 SKU Ids or 2 SKU json in an array

["skudID1", "skudID2"]
["SkuConfig1", "SkuConfig2"]

GlamAr.comparison("open", ["skudID1", "skudID2"]); // replace skudID1 and skudID2 with two SKU id's
GlamAr.comparison("close"); // When we send close we don't need to send SKUs

setExperience​

Switches between AR Try-On and Skin Analysis in the initialized SDK without reloading the full SDK. Wait for the loaded event before calling it.

import GlamAR

GlamAr.setExperience(experience: "vto", options: VtoExperienceOptions(category: "eyewear"))
GlamAr.setExperience(experience: "vto", options: VtoExperienceOptions(subCategory: "lipstick"))
GlamAr.setExperience(experience: "vto", options: VtoExperienceOptions(skuId: "sku-1"))
GlamAr.setExperience(
experience: "skinAnalysis",
options: SkinAnalysisExperienceOptions(appId: "your-app-id")
)
ParameterDescription
experienceRequired. Exactly vto or skinAnalysis (case-sensitive).
optionsRequired. VtoExperienceOptions for vto, or SkinAnalysisExperienceOptions for skinAnalysis.
category, subCategory, skuIdVTO selectors. Provide one nonblank string in the options. skuId is the exact merchant SKU from variants[].skuId, not a product ID or variant UUID.
appIdRequired nonblank Skin Analysis app ID in the options.

Selector values are trimmed. If multiple VTO selectors are supplied, the first nonblank value wins in this order: category, subCategory, skuId. Invalid experience/options emit experience-change-failed without switching.

This method returns no value. Listen for experience-changing, experience-changed, and experience-change-failed to track completion or failure.

open​

Use open and its mode variants only when you disable or override the SDK's built-in hero screen and implement your own screen or launch buttons. The built-in hero screen already provides buttons to open the SDK, so no open call is needed when using it. After applying a SKU, call the appropriate variant from your custom button handler.

GlamAr.open(mode: String? = nil, imgURL: String? = nil);

Opens the AR widget.
Return Value: None

ParametersTypeDescriptionOptions
modestringOpens Live-Tryon, Model/Image-tryon and Model ViewermodelViewer imgTryOn
imgURLstringValid image URLAny valid URL
  • No parameters: Start Live VTO

    GlamAr.open();
  • Model Viewer: Start Model Viewer

    GlamAr.open("modelViewer");
  • Image Try-On:

    • Opens the image/model selection screen:
      GlamAr.open("imgTryOn");
    • Opens try-on directly with a specific image:
      GlamAr.open("imgTryOn", "url_of_image");

Switching Views​

  • While in Live or Image mode, calling:

    GlamAr.open("modelViewer");

    will open the model viewer. Calling GlamAr.open() again returns to the selected Try-On type.

  • To switch from Live to Image mode, call:

    GlamAr.back();

    This resets the Try-On session and then call GlamAr.open() with desired parameter

Note: The SKU must already be applied. If not, the SDK will display an error.

Eye PD Measurement Flow​

We provide an integrated supports for eye pupillary distance (PD) scanning. This is activated when viewing any eyeware categories. If user wants to show his own UI and use this service we have function GlamAR.eyePD() for that case.

GlamAr.eyePD("start"); // To launch or restart Eye PD flow
GlamAr.eyePD("close"); // To exit Eye PD and return to active Try-On

Events​

The sku-applied event includes the applied SKU configuration in data. See the platform-specific callback examples there to read the correct payload shape.

The GlamAR SDK emits various events throughout its lifecycle to help you monitor state, respond to user actions, and handle success or failure cases.

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

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

Check Events Page for event details.