The GlamAR SDK provides tools to integrate augmented reality (AR) features into your iOS application. This document covers the installation, initialization, and usage of the SDK, including details about GlamArView
API, and GlamAr
instance API.
You can integrate GlamAR into your project using one of the following dependency managers:
- 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"
-
If you haven't already, install CocoaPods:
gem install cocoapods
-
In your project directory, create a
Podfile
if you don't have one:pod init
-
Add the following line to your Podfile:
pod 'GlamAR'
-
Run the following command:
pod install
-
Open the
.xcworkspace
file to work with your project in Xcode.
-
If you haven't already, install Carthage:
brew install carthage
-
In your project directory, create a
Cartfile
if 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.xcframework
fromCarthage/Build
to the "Frameworks, Libraries, and Embedded Content" section.
If you prefer not to use a dependency manager:
- Download the latest release of GlamAR from the releases page.
- Drag and drop
GlamAR.framework
into your Xcode project. - In your target's "General" settings, add GlamAR under "Frameworks, Libraries, and Embedded Content".
GlamAR depends on Alamofire. If you're using SPM, CocoaPods, or Carthage, this dependency will be automatically managed. If you're installing manually, ensure you also include Alamofire in your project.
After installation, import GlamAR in your Swift files:
import GlamAR
Now you're ready to use GlamAR in your project!
Initialize the SDK in your AppDelegate
to ensure it's set up when your app starts. By default, it will be pointing to development; set development
to false
for production.
import GlamAR
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GlamAr.initialize(accessKey: "YOUR_ACCESS_KEY", development: false)
return true
}
}
To use GlamArView
, add it to your view hierarchy:
import GlamAR
class ViewController: UIViewController {
@IBOutlet weak var glamArView: GlamArView!
override func viewDidLoad() {
super.viewDidLoad()
// Setup GlamArView
}
}
Start the preview in various modes using startPreview
:
glamArView.startPreview(previewMode: .none)
glamArView.startPreview(previewMode: .camera)
glamArView.startPreview(previewMode: .image("IMAGE_URL"), isBeauty: false)
Apply a SKU to the GlamArView
:
glamArView.applySku(skuId: "SKU_ID", category: "CATEGORY")
Clear the GlamArView
:
glamArView.clear()
Take a snapshot of the current view:
glamArView.snapshot()
Toggle between the original and AR-applied view:
glamArView.toggle(showOriginal: showingOriginal)
Fetch a list of SKUs:
GlamAr.getInstance().api.fetchSkuList(pageNo: 1, pageSize: 100) { result in
switch result {
case .success(let skuListResponse):
// Handle success
case .failure(let error):
// Handle failure
}
}
Fetch details of a specific SKU:
GlamAr.getInstance().api.fetchSku(id: "SKU_ID") { result in
switch result {
case .success(let item):
// Handle success
case .failure(let error):
// Handle failure
}
}
Here's a complete example demonstrating the usage of GlamAr
and GlamArView
:
import UIKit
import GlamAR
class ViewController: UIViewController {
private var showingOriginal = false
@IBOutlet weak var glamArView: GlamArView!
@IBAction func onApplyClick(_ sender: Any) {
self.glamArView.applySku(skuId: "666b311f-1b34-4082-99d1-c525451b44a1", category: "beauty")
}
@IBAction func onClearClick(_ sender: Any) {
self.glamArView.clear()
}
@IBAction func onToggleClick(_ sender: Any) {
showingOriginal = !showingOriginal
self.glamArView.toggle(showOriginal: showingOriginal)
}
@IBAction func onExportClick(_ sender: Any) {
self.glamArView.snapshot()
}
override func viewDidLoad() {
super.viewDidLoad()
self.glamArView.startPreview(previewMode: .none)
// Alternatively:
// self.glamArView.startPreview(previewMode: .camera)
// self.glamArView.startPreview(previewMode: .image("IMAGE_URL"), isBeauty: false)
}
}
Ensure you handle permissions appropriately, especially for camera access if using PreviewMode.camera
. Add the necessary privacy usage descriptions to your Info.plist
:
<key>NSCameraUsageDescription</key>
<string>We need access to your camera for AR features.</string>
This document provides a comprehensive overview of the GlamAR SDK for iOS, detailing how to install, initialize, and use its various components. Use this as a reference to integrate AR features into your iOS application effectively.