Developer Docs

Quickstart to integrating the TorchKit iOS SDK

The SDK allows any iOS application to load and execute Torch projects. You can find a full list of supported features here. The quickest way to see a running example of the SDK is to open and run the sample app. Finally, detailed API documentation is available here.

Running the SDK sample

The SDK includes a sample application that mimics a product catalog. In this case, it is a gallery of Torch projects. It includes a check to make sure the users device supports ARKit, if it does not, it will not allow access to the Torch project.

  1. Request an API key from Torch.
  2. Open AppDelegate.swift and replace the API key in this line: TorchKit.shared.initSDK(apiKey: "INSERT API KEY HERE")
  3. Update the Signing Settings under Build Settings to use your Apple account.
  4. Run the sample application on a device.

SDK integration using the SDK sample classes

The SDK sample contains a few helper classes that make it quick to integrate the TorchSDK into any application. If the application only needs to present a new view controller to display a Torch project, this is the fastest path to integration. If the application don’t have an existing view controller with SceneKit integrated, this is also the fastest path to integration. Finally, this path also deals with setting the project anchor which the raw SDK integration path skips over.

  1. Request an API key from Torch. (Fill this in)
  2. Export the Torch project that the application. (Link to export web site). Then add it to the application’s XCode project.
  3. Copy TorchProjectViewController.swift, ProjectAnchorManager.swift, Plane.swift, envmap.png into the project.
  4. Copy the TorchProjectViewController from the sample app storyboard into the application’s storyboard.
  5. Import TorchKit into the file that implements AppDelegate then add the following to AppDelegate.application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool:

    do {
      try TorchKit.shared.initSDK(apiKey: "YOUR_API_KEY")
    } catch {
      os_log(OSLogType.default, "Init failed!")
    }
  6. Add the following to AppDelegate.applicationWillTerminate(...):

    TorchKit.shared.shutdownSDK()
  7. Add Camera permission message. Add a string variable to the application’s Info.plist with the key of NSCameraUsageDescription and a value containing the message to display to the user when camera permissions are required.

  8. Finally, when the application needs to display a Torch project, add the following code:

    let vc = self.storyboard?.instantiateViewController(withIdentifier: "TorchProjectViewController") as! TorchProjectViewController
    vc.projectURL = Bundle.main.url(forResource: "myproject", withExtension: "torchkitproj")!
    self.present(vc, animated: true, completion: nil)

TorchProjectViewController can be used as the basis of a new UIViewController for the target application.

Full step by step guide to SDK integration

This is every detail needed to integrate a Torch project viewer in an application. For an example of how to deal with setting the project anchor, see ProjectAnchorManager.swift in the sample application.

  1. Request an API key from Torch. (Fill this in)
  2. Export the TorchProject that is going to be used as a .torchkitproj and add it to the XCode project.
  3. Import TorchKit into the file that implements AppDelegate then add the following to AppDelegate.application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool:

    do {
      try TorchKit.shared.initSDK(apiKey: "YOUR_API_KEY")
    } catch {
      os_log(OSLogType.default, "Init failed!")
    }
  4. Add the following to AppDelegate.applicationWillTerminate(...):

    TorchKit.shared.shutdownSDK()
  5. Add Camera permission message. Add a string variable to the application’s Info.plist with the key of NSCameraUsageDescription and a value containing the message to display to the user when camera permissions are required.

  6. Add an ARSCNView to the target view controller to display a SceneKit scene and use ARKit to control the camera.

  7. In the ViewController viewDidAppear method, call TorchGestureManager.addGestureRecognizers(to:) to add gesture recognizers for tap and object manipulation.

  8. Create a TorchProjectNode passing the path to the .torchkitproj in.

  9. Add the TorchProjectNode to the SceneKit scene.

  10. Create a CADisplayLink to call TorchProjectNode.tick(...) to advance project state.