构建pre_[教程] 5分钟构建AR应用

 构建一个应用是一件相当耗费成本的事情,更何况是AR应用!本文将通过三步骤轻松快速制作AR应用程序。

4dc97602fb3ff6db5ce63e814caac5a3.png

01

准备工作

在开始之前我们需要准备好框架包。我们可以前往 G ithub获取,目前为Pre-Rlease版本如果您在使用过程中出现任何问题请让我们知道。

02

创建和设置

紧接着我们需要使用我们的XCode创建App项目,这里我们选用XCode的版本为: 12.0.1 (12A7300)

目前我们Pre-Release了第一个版本的framework,有兴趣的小伙伴可前往下载使用。https://github.com/weacw/ARMODFramework/releases

bb64c0dae1d9bf69fff61a70e739c94e.png

创建App项目

3c77520f55ed12385c86b3a3f1160ea3.png

设置项目

将 ARMOD.framework 和 UnityFramework.framework 添加到XCode工程内(右键我们的项目选择 Add Files to)

63fc52344d65fa4e711befe7e38373d4.png

添加ARMOD

12a0ab34f097acc4fdf7daa25fb52a11.png

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即可。 

f042b8a92a67355b96e9ceda0b428cfb.png

关闭后我们重新 Command+B 再次构建,成功构建!

77e6ae2c30c6fc78788e60c427c6ca8a.png

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

ee6933ca39c42c3038c653531f5d6eac.png

使用USB连接手机,构建App 安装到我们的手机上 Command + R, 点击按钮即可进入AR世界!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值