ARKit from Apple continues to evolve, letting devs engage users on deeper levels than ever.

by Jill Scott

As companies from all industries seek new ways to engage with audiences, we at productOps are using augmented reality as a means of elevating mobile apps from the informative to the experiential.

With ARKit, Apple provides a robust SDK for building AR experiences for the iPhone. It allows developers to use the iPhone camera to place and manipulate objects in a 3D space. This blog provides a quick glance at ARKit, its engaging features, impressive visuals, and widely applicable toolkit. With the release of ARKit 2, even more features are available for devs, including persistent experiences, shared experiences, object detection and tracking.

I made a quick and dirty Pokemon Go-like prototype to demonstrate the ease with which interactive features can be implemented into mobile. Familiarity with Swift is helpful, but no experience necessary to follow along!

What are AR and ARKit?

What does AR mean to developers? Let’s start with the Wikipedia definition:

Augmented reality (AR) is an interactive experience of a real-world environment where the objects that reside in the real-world are "augmented" by computer-generated perceptual information.

You may already be familiar with the popular AR app called Pokemon Go! You hold up your phone’s camera, and you can see the environment around you on the screen, but with a little critter added that you can “catch”. We will return to this example later, as a sort of basis for our AR tutorial.

Image result for pokemon go
Image courtesy of PokemonGoLive

AR can be categorized into two types of experience: constructive and destructive. The former adds elements to the environment, while the latter takes them away. As a basic example, imagine an interior design app. A constructive AR experience would let you see what a new couch would look like in your space, while a destructive one would let you see what your space would look like sans that old college craigslist sofa.

Why do we care about mobile AR?

What’s the point? Why integrate AR experiences for mobile users?

  1. It’s engaging. It integrates into a users’ life in a way many other application features cannot. Users interact with a product or idea on a new level and see how it fits into the world around them.
  2. It’s advanced. While relatively simple to integrate, the results are technologically striking.
  3. It’s helpful. See this Tom’s Guide article to see how AR is being used to create genuinely useful tools from learning languages to exploring museums to selecting makeup.

Our App

For a tutorial, we’re going to create what I’ve affectionately dubbed “Janky Pokemon”. It’s a quick and dirty recreation of a Pokemon Go-like app. It won’t be appstore-ready, but it will demonstrate how straight-forward it can be to set up a basic AR experience.

We will start small. Let’s get our project set up and an object showing on our screen.

Project Setup: First Steps

First create a storyboard and add an AR scene view to your view controller:

Now create a new view controller, add your imports, conform to the ARKit delegate protocol, and create an IBOutlet connecting to your scene view:

Set up the scene view in your viewDidLoad and run it in your viewWillAppear:

 
We want to pause the session if we leave the view:

Now let’s create a function to add a simple box to the environment:

Now just call that function in viewDidLoad and run. You will have to run this on your phone, as you need camera access!

Did you crash?  “The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.” Apple doesn’t want to allow just any ol’ app to take over your camera. You will have to add a line to your plist to request camera permissions. Navigate to your Info.plist and add the line:

Let’s try again. Click run, allow camera, and hold up your phone. If you look around with your phone a bit, you should see a floating purple box nearby!

You may actually find yourself inside the purple box, in which case step back a bit. We will correct this personal space violation in Part 2 of this series! I will also explain how positioning works in ARKit, add some new shapes and texture, and learn how to make objects move.