Quickstart in iOS Swift
Integrate the ARwayKit SDK with iOS Swift
Last updated
Integrate the ARwayKit SDK with iOS Swift
Last updated
In this quickstart guide, we will be integrating the ARwayKit SDK with iOS Swift. This example will be using to integrate into an iOS app.
In this guide, we will be using the following versions:
Xcode: 14.3
Unity: 2022.3.29f1 LST
Download the ARwayKit SDK project from GitHub as a ZIP. You can for access to the ARwayKit SDK.
For this example a new iOS app called "SwiftUnity" will be created with interface "Storyboard" and language "Swift".
When opening the project in Unity for the first time, you will need to build the Addressables Groups.
Switch the build platform to either iOS or Android
"File-> Build Settings..." then select the Android or iOS as the Platform.
Click "Switch Platform" on the bottom right.
Navigate to "Window -> Asset Management -> Addressable -> Groups".
In the Addressables Groups window, click on "Build -> New Build -> Default Build Script".
In the Console window, you should see the success message "Addressable content successfully built".
Steps
In Unity select File -> Build Settings.
Switch the Platform to iOS.
Select option "Build Project".
Export the ARwayKit Unity SDK to a new folder and name it "iOSBuild" and place it in the base directory for the iOS project.
Xcode workspace allows to work on multiple projects simultaneously and combine their products
Open your Xcode project.
All the steps are done from just created Workspace project.
With this step we add Unity player in the form of a framework to NativeiOSApp, it does not change the behavior of NativeiOSApp yet
Select NativeiOSApp target from NativeiOSApp project.
In "General" tab / "Frameworks, Libraries, and Embedded Content" press +.
Add Unity-iPhone/UnityFramework.framework.
In "Build Phases" tab, expand "Link Binary With Libraries".
Remove UnityFramework.framework from the list (select it and press - ).
By default Data folder is part of Unity-iPhone target, we change that to make everything encapsulated in one single framework file.
Change Target Membership for Data folder to UnityFramework.
Next, open Info.plist and add the following rows:
Privacy - Microphone Usage Description: Used for creating audio content
Privacy - Camera Usage Description: Used for AR Content and mapping
Privacy - Location Usage Description: Used to attach maps with global coordinates and public map searching
Privacy - Location When in Usage Description: Used to attach maps with global coordinates and public map searching
Privacy - Photo Library Usage Description: This app requires access to save media
Privacy - Photo Library Additions Usage Description: This app requires access to save media
To create an entry point to SwiftUI, create a new SwiftUI view called ContentView.swift and add a single button to launch ARway.
Next, update the ViewController.swift file to match the following.
Next, implement the connection between the Unity SDK and the Swift app. A new singleton called Unity.swift is created with the following code.
Next update the AppDelegate.swift file to pass the main window reference to Unity.
You should now be able to build and run the project on an iOS device.
Create workspace and save it as both.xcworkspace. (File / New / Workspace).
Add SwiftUnity.xcodeproj and generated Unity-iPhone.xcodeproj from step #2 to workspace on a same level ( File / Add Files to “both” ).