Augmented Reality (AR) Guideline in iOS

Augmented Reality

06 October, 2022

Augmented Reality
KrunaL Chunibhai Parvadiya

KrunaL Chunibhai Parvadiya

CEO, Softices

To create your first RealityKit app with Swift, you will need to have updated to MacOS Catalina. Neither of these new frameworks will work on MacOS Mojave or any earlier version. You should also make sure you have the latest version of Xcode by checking the Mac App Store and checking that there are no updates for Xcode that you have not yet installed. Having the latest version of Xcode and MacOS is essential to making sure this app works correctly. You will also need an iPad, as AR can’t be emulated by the iOS Simulator.

Create your First AR App with RealityKit, QLPreviewController and Swift

Step 1:

To create this project in Xcode, go to File > New > Project and select the Augmented Reality App template.

ar guideline in iOS step 1

Step 2:

Set your app name and Language in select Swift, then Content Technology in select RealityKit.

ar guideline in iOS step 2

Step 3:

The app needs access to the camera: Open the target configuration and add a Privacy - Camera Usage Description key to the Info.plist. Set a description why the camera is needed.

ar guideline in iOS step 3

Step 4:

Here we have added two dummy animation files (file type: .usdz) of AR Object, AR Quick Look for downloading animation files.

ar guideline in iOS step 4.1


ar guideline in iOS step 4.2

Step 5:

Then next we have added one viewcontroller, and set one button inside the viewcontroller.

ar guideline in iOS step 5

Step 6:

And finally here is the code of the AR object showing viewcontroller, in this screen we have present QLPreviewController for AR object animation showing.

ar guideline in iOS step 6

Finally the Result is Here

ar guideline in iOS result

ViewController File Code:


import UIKit

import RealityKit

import QuickLook


class ViewController: UIViewController {


//MARK: ViewController Lifecycle

override func viewDidLoad() {

super.viewDidLoad()


}


//MARK: Button Action

@IBActionfuncClick_PressHere(_ sender: UIButton) {

let previewController = QLPreviewController()

previewController.delegate = self

previewController.dataSource = self

self.present(previewController, animated: true, completion: nil)

}

}


//MARK: QLPreviewController Delegate & DataSource Methods

extension ViewController: QLPreviewControllerDelegate, QLPreviewControllerDataSource {


func numberOfPreviewItems(in controller: QLPreviewController) -> Int {

return 1

}


func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {


guard let path = Bundle.main.path(forResource: "toy_drummer", ofType: "usdz") else { fatalError("Couldn't find a model") }


let url = URL(fileURLWithPath: path)

return url as QLPreviewItem

}

}


Augmented Reality in ios

Previous

How Augmented Reality (AR) Works in iOS

Next

Django

Django