iOS small skills: integration scheme with uni-app and unity

This article is participating in the "Golden Stone Project"

introduction

Project background: iOS app is embedded with H5 and AR functions, and AR is developed using unity2020.

Technical point: The target project exported by unity Unity-iPhone.xcodeprojis integrated with the original

Current solution: uniapp bridges IOS, ios bridges unity, uniapp develops iOS native code in the form of a plug-in, and then integrates it into an ipa file.

I Implementation ideas

Idea 1: uniapp bridges IOS, ios bridges unity, and then integrates it into an ipa file.

What Unity publishes to the iOS platform is an Xcode project, and uniapp is a local resource package.

Idea 2: Native APP integrates the Xcode project exported by Unity (the exported project needs to be packaged as a static library) zhuanlan.zhihu.com/p/103759507www.jianshu.com/p/00dcac5b2…

Idea 3: Unity3D embeds iOS native code www.jianshu.com/p/82e34d9a1…

Idea 4: The web project exported by Unity is deployed to the server, and the native APP loads the corresponding H5 address. (Video AR does not support web export)

The AR of the applet is image recognition, and the augmented reality AR is space recognition; the applet is on the screen, and the app can follow the picture in 3D.

If you have better ideas and related articles, please leave a message for exchange.

II bridging

2.1 The method of calling Unity in IOS

insert image description here

insert image description here

Use the C interface UnitySendMessage provided by unityengine.dll. The first char* indicates the name of the GameObject that receives the message, the second indicates the name of the function that receives the message in the script of the GameObject, and the third indicates the passed parameter.

    //参数1 场景中模型的名字
    //参数2 脚本名称方法
    //参数3 想unity传递一个char类型的数据
   UnitySendMessage("iOSSendMessageToUnity""ChangeCameraDirection""");
复制代码

结合后unity里面的你先打开后是进入这个场景(SelectScene) 物体名SceneManager 脚本名SceneSelect 函数ChangeScene(string str) 传参数ZhenWuMiaoAR就是真武庙;或者传参数modelShow就是沙盘。

2.2 uniapp 桥接iOS

除了 uni-app 框架内置的跨端 API,各端自己的特色 API 也可通过条件编译 自由使用。因此uniapp可直接使用原生API进行发布通知,实现通信。 insert image description here

insert image description here

在这里插入图片描述

III uni-app运行原理

kunnan.blog.csdn.net/article/det…

3.1 js引擎

浏览器的js引擎,就是jscore或v8的基础上新增了一批浏览器专用API,比如dom;

node.js引擎,则是v8基础上补充一些电脑专用API,比如本地io;

uni-app的App端和小程序端的js引擎,其实是在jscore上补充了一批手机端常用的JS API,比如扫码。

3.2 运行原理

uni-app 在非H5端运行时,从架构上分为逻辑层和视图层两个部分。

  1. 逻辑层负责执行业务逻辑,也就是运行js代码。

逻辑层是运行在一个独立的jscore里的,它不依赖于本机的webview,所以一方面它没有浏览器兼容问题,可以在Android4.4上跑es6代码,另一方面,它无法运行window、document、navigator、localstorage等浏览器专用的js API。

  1. 视图层负责页面渲染。

h5和小程序平台,以及app-vue,视图层是webview。

而app-nvue的视图层是基于weex改造的原生渲染视图。

3.3 编译器

vue2:uni-app编译器基于wepback实现

vue3:uni-app编译器基于Vite实现,编译速度更快

HBuilderX 3.3.0+ , uni-app在App/H5/小程序全平台支持Vue 3.0开发,且全平台支持Vite编译器。

Webpack1
   |
   |
Rollup 出现(推崇 ESM 规范,可以实现 tree shaking, 打包出来的代码更干净)
   |
   |
Webpack2(也实现了 tree shaking, 但是配置还是太繁琐了)
   |
   |
Parcel (号称 0 配置)
   |
   |
Webpack4(通过 mode 确定 development 和 production 模式,各个模式有自己的默认配置)
   |
   |
Webpack5(持久化缓存、module federation)
   |
   |
Esbuild(采用 go 语言开发,比 Webpack 更快)
   |
   |
Vite(推崇 ESM 规范,开发模式采用 nobundle,更好的开发体验)
复制代码

Component modularization has become the mainstream mode of front-end development. Take React and Webpack as examples: split all the functions involved in an application into components, each component corresponds to a source file, and then package these source files through Webpack. During the development process, you can open a local server through Webpack to view the running effect of the code in real time.

IV Frequently Asked Questions

4.1 Devices that support ARCore

developers.google.cn/ar/devices#…

4.2 Mixed development of uni-app and native App

First of all, be sure to confirm uni-app and native code, who is the master and who is the slave.

uniapp.dcloud.io/hybrid.html

  1. If your application is developed by uni-app and needs to expand some native capabilities, first go to the plug-in market to see if there are any ready-made plug-ins. If not, develop native plug-ins yourself.
  2. If your app is developed natively, and some functional columns want to be implemented through uni-app, there are two ways: a. Integrate the uni applet sdk in the native app, and then run the front end of the applet developed with the uni-app framework Project (mini program application resource package wgt). nativesupport.dcloud.net.cn/README b. If you don't want to integrate the native SDK, then publish the uni-app code as H5, and open it through webview in the native App.

see also

Official account: iOS reverse engineering

Guess you like

Origin juejin.im/post/7208897614824325178