ar_tourism_flutter_unity/READMEIOS.md

111 lines
3.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### Unity 导出设置iOS
1. 在 Unity 中选择`File > Build Settings > iOS`
2. 配置项:
- 确保`Export Project`被勾选
- 脚本后端选择`IL2CPP`
- 勾选`Development Build`用于调试
- 目标架构选择`ARM64`
- 在`Player Settings > Other Settings`中:
- 设置 Bundle Identifier: `com.example.arTourismFlutterUnity`
- 最低 iOS 版本: 12.0
- 设置必要的权限(Camera, Location 等)
3. 导出项目后,将整个导出的 Unity-iPhone 项目复制到 Flutter 项目的`ios/UnityLibrary`目录
### Info.plist 配置
确保 Info.plist 文件包含所有必要的权限描述:
```xml
<!-- 相机权限 -->
<key>NSCameraUsageDescription</key>
<string>此应用需要使用相机进行AR体验</string>
<!-- 相册权限 -->
<key>NSPhotoLibraryUsageDescription</key>
<string>需要相册权限用于保存和选择媒体</string>
<!-- 麦克风权限 -->
<key>NSMicrophoneUsageDescription</key>
<string>此应用需要访问您的麦克风以提供录像服务</string>
<!-- 定位权限 -->
<key>NSLocationWhenInUseUsageDescription</key>
<string>此应用需要访问您的定位以提供导航服务</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>App需要您的同意,才能始终访问位置</string>
```
## 跨平台数据交互
Unity 与 Flutter 之间通过 MethodChannel 进行数据交互:
```dart
// 在Flutter中
static const platform = MethodChannel('com.example.ar_tourism_flutter_unity.unity');
// 调用Unity方法
await platform.invokeMethod('start_unity', {
'token': userToken,
'sceneName': 'Main',
'returnToHome': true
});
// 接收Unity消息
platform.setMethodCallHandler((call) async {
switch (call.method) {
case 'onUnityMessage':
// 处理来自Unity的消息
break;
case 'onUnityBackPressed':
// 处理Unity返回事件
break;
}
});
```
## iOS 打包流程
1. 更新版本号:
- 在`pubspec.yaml`中更新版本号
- 在 Xcode 中更新版本号和构建号:
在 Xcode 左侧导航栏中点击最顶部的 "Runner" 项目
在中间区域确保选中 "Runner" target不是 Project
点击上方的 "General" 标签
向下滚动找到 "Identity" 部分,里面有两个重要的版本号设置:
Version (显示版本号)
Build (构建版本号)
确保 与p0ubspec.yaml 中的版本号一致
2. 配置签名和证书:
- 在 Xcode 中配置正确的签名证书和配置文件
3. 构建和归档:
```
flutter build ios --release
```
然后在 Xcode 中进行归档和上传到 App Store
## 注意事项
1. 内存管理iOS 系统内存限制较严格,需确保 Unity 资源及时释放
2. Framework 路径:确保 UnityFramework.framework 在正确的路径并被正确引用
3. 权限处理:提前在 Info.plist 中配置所有必要权限
4. Bitcode 禁用Unity 不支持 Bitcode需在项目配置中禁用
5. 架构兼容:确保所有库使用兼容的架构(推荐仅使用 ARM64
# iOS
包名com.example.arTourismFlutterUnity
打开 Xcode 项目:
Apply to README.md
Run
在 Xcode 中,右键点击项目导航器中的项目根目录
选择"Add Files to 'Runner'..."
导航到项目的 ios/UnityLibrary 目录
确保选中"Create folder references"(创建文件夹引用)选项
点击"Add"按钮
Flutter 3.19.3 ; Flutter Unity Widget 2022.2.1 ; Xcode16.3 ;build version 16E140;pod 1.16.2;