iOS
We provide Swift SDK distributed by CocoaPods for your iOS apps to present AR-sessions, easily.
Installation
To integrate Meshkraft into your Xcode project using CocoaPods, add it to your Podfile
:
pod 'Meshkraft'
Then, run the following command:
$ pod install
Usage
Initialization
-
Import
Meshkraft
framework header in yourAppDelegate
import Meshkraft
-
Add the following to your
AppDelegate
application:didFinishLaunchingWithOptions:
method.Meshkraft.setApiKey("YOUR_API_KEY")
Make sure to replace
YOUR_API_KEY
with your application token.
AR Session
Import Meshkraft
framework header
import Meshkraft
Start an AR session with product SKU:
Meshkraft.meshkraft().startARSession(productSKU: "YOUR_PRODUCT_SKU")
To receive model loading status notifications , conform to MeshkraftDelegate
protocol:
Meshkraft.meshkraft().delegate = self
extension ViewController : MeshkraftDelegate {
func modelLoadStarted() {
print("load started")
activityIndicator.startAnimating()
}
func modelLoadFinished() {
print("load finished")
activityIndicator.stopAnimating()
}
func modelLoadFailed(message: String) {
print("load failed message: \(message)")
activityIndicator.stopAnimating()
}
}
VTO Session
Start a VTO session with product SKU:
Meshkraft.meshkraft().startVTOSession(productSKU: "YOUR_PRODUCT_SKU")
The VTO session requires camera access, so make sure to add the necessary permissions to your Info.plist
file. Add the following keys with their respective descriptions:
<key>NSCameraUsageDescription</key>
<string>Your description for why the app needs camera access.</string>
Replace "Your description for why the app needs camera access." with a suitable explanation for your users.
Availability API
You can check the availability of the Meshkraft service for specific SKUs by calling:
Meshkraft.meshkraft().checkAvailability(sku: "SKU1,SKU2", completion: { (result: AvailabilityResult?, errorMessage) in
if let result = result {
for (sku, availability) in result {
print("SKU: \(sku), AR Available: \(availability.ar), VTO Available: \(availability.vto)")
}
} else {
print("Failed to check availability: \(errorMessage ?? "Unknown error")")
}
})
The AvailabilityResult
is a dictionary where the key is the SKU and the value is a MeshkraftAvailability
object containing ar
and vto
flags indicating the availability of AR and VTO sessions for the given SKU.
Check Device Support
You can check if AR is supported on the device:
Meshkraft.isARSupported()
Model URL
Get AR model URL with product SKU:
Get the modelURL
from the completion block, check the errorMessage
for any possible errors.
Meshkraft.meshkraft().getModelURL(productSKU: "YOUR_PRODUCT_SKU", completion: {(modelUrl, errorMessage) in
print("modelUrl: \(modelUrl ?? "")")
print("errorMessage: \(errorMessage ?? "")")
})