“ 构建一个应用是一件相当耗费成本的事情,更何况是AR应用!本文将通过三步骤轻松快速制作AR应用程序。”
01
—
准备工作
在开始之前我们需要准备好框架包。我们可以前往 G ithub获取,目前为Pre-Rlease版本如果您在使用过程中出现任何问题请让我们知道。02
—
创建和设置
紧接着我们需要使用我们的XCode创建App项目,这里我们选用XCode的版本为: 12.0.1 (12A7300)目前我们Pre-Release了第一个版本的framework,有兴趣的小伙伴可前往下载使用。https://github.com/weacw/ARMODFramework/releases
创建App项目
设置项目
将 ARMOD.framework 和 UnityFramework.framework 添加到XCode工程内(右键我们的项目选择 Add Files to)
添加ARMOD
Command + B 构建我们的App,此时会出现错误!
ld: '/Users/nswell/Documents/Git/CellStudio/Apps/Made With ARMOD/Challenge5minutesARApp/Challenge5minutesARApp/ARMOD.framework/ARMOD' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. file '/Users/nswell/Documents/Git/CellStudio/Apps/Made With ARMOD/Challenge5minutesARApp/Challenge5minutesARApp/ARMOD.framework/ARMOD' for architecture arm64clang: error: linker command failed with exit code 1 (use -v to see invocation)
此错误是因为AR-MOD不支持BitCode故我们关闭BitCode即可。
关闭后我们重新 Command+B 再次构建,成功构建!
03
—
编码对接
Import ARMOD
前往 AppDelegate.swift 找到函数并增加AR-MOD初始启动项。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. //新增加d的代码,用于配置启动项 ARMODAPI.initLaunchingOptions(launchOptions) return true }
前往 SceneDelegate.swift 找到函数并增加AR-MOD初始Window。增加代码如下
ARMODAPI.initUIWindow(window: window)
修改后代码如下:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). // Get the managed object context from the shared persistent container. let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext // Create the SwiftUI view and set the context as the value for the managedObjectContext environment keyPath. // Add `@Environment(\.managedObjectContext)` in the views that will need the context. let contentView = ContentView().environment(\.managedObjectContext, context) // Use a UIHostingController as window root view controller. if let windowScene = scene as? UIWindowScene { let window = UIWindow(windowScene: windowScene) window.rootViewController = UIHostingController(rootView: contentView) self.window = window window.makeKeyAndVisible() //新增加代码 ARMODAPI.initUIWindow(window: window) } }
编辑 ContentView.swift 往 Body增加按钮进行AR的触发!
//// ContentView.swift// Challenge5minutesARApp//// Created by NSWell on 2020/10/4.//import SwiftUIimport ARMODstruct ContentView: View { var body: some View { Text("Hello, world!") .padding() Button(action: { //ARMOD触发代码 let dev = try! DeveloperMapper(appUid: "通过Dashboard获取", developerUid: "通过Dashboard获取", clientID: "", clientSecret: "") ARMODAPI.authSDK(developerMapper: dev) ARMODAPI.showView() ARMODAPI.fetchData(project_uid: "通过Dashboard获取") }, label: { /*@START_MENU_TOKEN@*/Text("Button")/*@END_MENU_TOKEN@*/ }) }}struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() }}
编辑 info.plist 文件,为ARMOD增加访问相机的权限。
NSCameraUsageDescription
使用USB连接手机,构建App 安装到我们的手机上 Command + R, 点击按钮即可进入AR世界!