

English
App packaging provides configuration Info.plist and Bundle Resources in iOS native development. Common items are encapsulated in uni-app, and manifest.json is provided.
But manifest.json cannot contain all iOS configuration.
Before HBuilderX 3.6.5, developers could only package or develop [App native language plug-ins](https://nativesupport.dcloud .net.cn/NativePlugin/README).
Starting from HBuilderX3.6.5, it supports directly configuring the Info.plist and resource files (Bundle Resources) of the iOS platform in the application project.
Info.plist
文件是 XCode 工程配置文件,可在HBuilderX中项目中添加Info.plist
文件,云端打包后将会合并到 XCode 工程生成 ipa。
Edit and add the required content according to the application requirements, as shown in the following example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>My_Custom_String_Key</key>
<string>My_Custom_String_Value</string>
<key>My_Custom_Array_Key</key>
<array>
<dict>
<key>My_Custom_Array_Item_Key</key>
<string>My_Custom_Array_Item_Value</string>
<key>My_Custom_Array_Item_Key2</key>
<string>My_Custom_Array_Item_Value2</string>
</dict>
</array>
</dict>
</plist>
Notice
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
如果应用需要修改隐私信息访问的许可描述,可根据需求在Info.plist
文件中添加,如下示例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPhotoLibraryUsageDescription</key>
<string>读取相册的许可描述</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>读写相册的许可描述</string>
<key>NSCameraUsageDescription</key>
<string>使用摄像头的许可描述</string>
<key>NSMicrophoneUsageDescription</key>
<string>使用麦克风的许可描述</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>运行期访问位置信息的许可描述</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>后台运行期访问位置信息的许可描述</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>访问位置信息的许可描述</string>
<key>NSUserNotificationsUsageDescription</key>
<string>使用推送通知的许可描述</string>
<key>NSCalendarsUsageDescription</key>
<string>访问日历的许可描述</string>
<key>NSContactsUsageDescription</key>
<string>访问通讯录的许可描述</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>使用蓝牙的许可描述</string>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>持续使用蓝牙的许可描述</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>使用系统语音识别的许可描述</string>
<key>NSRemindersUsageDescription</key>
<string>访问提醒事项的许可描述</string>
<key>NSMotionUsageDescription</key>
<string>访问运动与健身的许可描述</string>
<key>NSHealthUpdateUsageDescription</key>
<string>更新健康数据的许可描述</string>
<key>NSHealthShareUsageDescription</key>
<string>分享健康数据的许可描述</string>
<key>NSAppleMusicUsageDescription</key>
<string>访问媒体资料库的许可描述</string>
<key>NFCReaderUsageDescription</key>
<string>使用NFC的许可描述</string>
<key>NSHealthClinicalHealthRecordsShareUsageDescription</key>
<string>访问临床记录信息的许可描述</string>
<key>NSHomeKitUsageDescription</key>
<string>访问HomeKit数据的许可描述</string>
<key>NSSiriUsageDescription</key>
<string>访问Siri的许可描述</string>
<key>NSFaceIDUsageDescription</key>
<string>使用FaceID的许可描述</string>
<key>NSLocalNetworkUsageDescription</key>
<string>使用本地网络的许可描述</string>
<key>NSUserTrackingUsageDescription</key>
<string>跟踪用户活动的许可描述</string>
</dict>
</plist>
注意
uni-app x项目manifest.json中没有提供iOS隐私信息访问许可描述的配置,需在此Info.plist中添加。
配置许可描述时需根据应用实际情况准确描述用途,否则提交AppStore审核可能被拒。
相关参考
如果应用需要向系统注册url scheme,以便在浏览器中通过scheme打开App,可根据需求在Info.plist
文件中添加CFBundleURLTypes
数据,如下示例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>scheme</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myappuniappx</string>
</array>
</dict>
</array>
</dict>
</plist>
uni-app/uni-app x项目都支持通过此方式配置url scheme,uni-app项目还可通过manifest.json的可视化界面配置,参考iOS设置url scheme
注意
CFBundleURLSchemes
字段下的字符串数组项是需要注册的scheme值,上面示例配置了myappuniappx
,请根据应用实际需求修改,array可添加多个string项配置多个scheme值。为了避免与其他应用产生冲突,请配置自己应用特有的字符串来避免冲突。CFBundleURLName
字段下的字符串是这组url scheme的标识,建议按上面示例的默认值配置即可,如需修改请参考苹果官方文档。CFBundleTypeRole
字段下的字符串是固定值,不要修改。相关参考
应用默认可支持的横竖列表:
如果希望自定义配置应用可支持的横竖屏列表,可根据需求在Info.plist
文件中添加UISupportedInterfaceOrientations
数据,如下示例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UISupportedInterfaceOrientations~iphone</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
uni-app 项目同时也支持在 manifest.json 中配置 screenOrientation,云端打包会与 Info.plist 中配置的值合并
uni-app x 项目仅支持 Info.plist 中配置,需 HBuilderX4.22+ 版本,提交云端打包后才能生效
注意
UISupportedInterfaceOrientations~iphone
字段下配置的是 iPhone 设备可支持的横竖屏UISupportedInterfaceOrientations~ipad
字段下配置的是 iPad 设备可支持的横竖屏UIInterfaceOrientationPortrait
竖屏主方向UIInterfaceOrientationPortraitUpsideDown
竖屏反方向,仅 iPad 设备支持UIInterfaceOrientationLandscapeLeft
横屏主方向UIInterfaceOrientationLandscapeRight
横屏反方向Enter the name nativeResources
(note that it is case-sensitive), confirm and create a directory.
Resources
,用于保存Bundle资源的目录UniApp.entitlements
,用于配置工程Capabilities
的文件在 XCode 中可以通过项目可视化界面编辑应用的Capabilities
,实际上是操作项目的 entitlements 和 Info.plist 文件保存数据。在 HBuilderX 中暂未提供Capabilities
可视化界面操作,需手动编辑UniApp.entitlements
和Info.plist
文件来实现相关配置。
在 nativeResources/ios 目录下创建UniApp.entitlements
文件,用于配置 XCode 原生工程的Capabilities
,如下示例:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
uni-app/uni-app x 项目可以通过编辑UniApp.entitlements
文件配置Capabilities
,需确保此entitlements文件格式正确,可以在 XCode 中编辑验证此文件。
注意
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
UniApp.entitlements
的内容只能用于配置 Capabilities
,不能添加自定义数据相关参考
Associated Domains
在UniApp.entitlements
添加com.apple.developer.associated-domains
节点数据开启Associated Domains
能力
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:demo.dcloud.net.cn</string>
</array>
</dict>
</plist>
注意
com.apple.developer.associated-domains
字段值类型必须是字符串数组applinks:demo.dcloud.net.cn
配置的是通用链接域名,其中applinks:
表示此域名用于通用链接,demo.dcloud.net.cn
是域名,请修改为应用自己使用的域名array
节点下可添加多个关联域名相关参考
PrivacyInfo.xcprivacy用于配置应用隐私清单文件,详情参考uni-app/uni-app x如何配置隐私清单。
将需要添加的iOS原生资源文件拷贝到Resources目录,云端打包时将会合并到安装包的.app中。
Notice
├─Pandora //uni-app资源目录
│ └─apps //应用资源目录
│ └─[AppID] //使用DCloud AppID作为目录名称
├─PandoraApi.bundle //uni-app SDK内置资源目录
├─control.xml //uni-app模块配置文件
├─dcloud_logo@2x.png //应用logo图片
├─dcloud_logo@3x.png //应用logo图片
├─uni-jsframework.js //uni-app vue2框架
├─uni-jsframework-vue3.js //uni-app vue3框架
├─uni-jsframework-dev.js //uni-app vue2框架(开发模式)
├─uni-jsframework-vue3-dev.js //uni-app vue3框架(开发模式)
├─unincomponents.ttf //uni-app内置字体图标
└─userPosition@2x.png //地图模块当前位置图标
├─uni-app-x //uni-app x 项目资源
├─DCUniVideo //video组件目录
├─uni_uts_toast_error.png //uni.showToast 使用的图标
└─uni_uts_toast_success.png //uni.showToast 使用的图标
HBuilderX 4.71 及以上版本新增支持嵌入 Watch App
uni-app/uni-app x 本身还不支持直接用于开发 Watch App。如果已经存在使用 XCode 开发完成的 Watch App,可以将其添加到使用 uni-app/uni-app x 开发的主应用中,提交云端打包即可嵌入到 ipa 中提交。
在 uni-app/uni-app x 项目原生资源目录 “nativeResources” 的 “ios” 目录下创建 “Watch”子目录,并添加 Watch App 二级制文件,结构如下:
├─nativeResources // App原生资源目录
│ └─ios // iOS平台目录
│ ├─Resources //资源文件存放目录,可选
│ ├─Watch //Watch App目录,可选
│ │ └─myWatchApp.app //需要添加的 Watch App 二进制文件
│ ├─ios-watch.json //Watch App 配置文件,可选
│ └─info.plist //应用主 info.plist 配置文件,可选
└─manifest.json // uni-app/uni-appx 项目清单文件
uni-app/uni-app x 中要添加的 Watch App 可执行文件。
需在原生 XCode 环境中添加 Watch Target,选择 “Watch App for Existing iOS App”,并在 XCode 中完成开发调试后编译并以发布方式导出包含此 Watch App 的 ipa 包,将 ipa 解压后在 Payload/XXX.app/Watch/ 目录下可以找到对应的 .app 文件。
将此 .app 文件添加到如上所示 uni-app/uni-app x 项目的 nativeResources -> ios -> Watch 目录中。
可选配置文件,仅在需要配置 Watch App 的包名和profile文件时使用,格式如下:
{
"myWatchApp.app": {
"identifier": "com.my.app.watch",
"profile": "embedded.mobileprovision"
}
}
When packaging offline, the application manifest file and resources need to be manually merged into the XCode native project by the developer.