移动配置
如果您的 Meteor 应用程序面向 iOS 或 Android 等移动平台,您可以在一个名为 mobile-config.js
的特殊顶级文件中配置应用程序的元数据和构建过程,该文件不包含在您的应用程序中,仅用于此配置。
以下代码片段是一个 mobile-config.js
文件示例。本节的其余部分将更详细地解释具体的 API 命令。
// This section sets up some basic app metadata, the entire section is optional.
App.info({
id: 'com.example.matt.uber',
name: 'über',
description: 'Get über power in one button click',
author: 'Matt Development Group',
email: '[email protected]',
website: 'http://example.com'
});
// Set up resources such as icons and launch screens.
App.icons({
'iphone_2x': 'icons/[email protected]',
'iphone_3x': 'icons/[email protected]',
// More screen sizes and platforms...
});
// Before Meteor 2.6 we had to pass device specific splash screens for iOS, but this behavior was dropped in favor of story board images.
App.launchScreens({
// iOS
// For most cases you will only need to use the 'ios_universal' and 'ios_universal_3x'.
'ios_universal': { src: 'splash/[email protected]', srcDarkMode: 'splash/Default@2x~dark.png' }, // (2732x2732) - All @2x devices, if device/mode specific is not declared
'ios_universal_3x': 'splash/[email protected]', // (2208x2208) - All @3x devices, if device/mode specific is not declared
// If you still want to use a universal splash, but want to fine-tune for the device mode (landscape, portrait), then use the following keys:
'Default@2x~universal~comany': 'splash/Default@2x~universal~comany.png', // (1278x2732) - All @2x devices in portrait mode.
'Default@2x~universal~comcom': 'splash/Default@2x~universal~comcom.png', // (1334x750) - All @2x devices in landscape (narrow) mode.
'Default@3x~universal~anycom': 'splash/Default@3x~universal~anycom.png', // (2208x1242) - All @3x devices in landscape (wide) mode.
'Default@3x~universal~comany': 'splash/Default@3x~universal~comany.png', // (1242x2208) - All @3x devices in portrait mode.
// However, if you need to fine tune the splash screens for the device idiom (iPhone, iPad, etc).
'Default@2x~iphone~anyany': 'splash/[email protected]', // (1334x1334) - iPhone SE/6s/7/8/XR
'Default@2x~iphone~comany': 'splash/[email protected]', // (750x1334) - iPhone SE/6s/7/8/XR - portrait mode
'Default@2x~iphone~comcom': 'splash/[email protected]', // (1334x750) - iPhone SE/6s/7/8/XR - landscape (narrow) mode
'Default@3x~iphone~anyany': '[email protected]', // (2208x2208) - iPhone 6s Plus/7 Plus/8 Plus/X/XS/XS Max
'Default@3x~iphone~anycom': { src: 'splash/[email protected]', srcDarkMode: 'splash/Default@3xiphoneanycom~dark.png' }, // (2208x1242) - iPhone 6s Plus/7 Plus/8 Plus/X/XS/XS Max - landscape (wide) mode
'Default@3x~iphone~comany': '[email protected]', // (1242x2208) - iPhone 6s Plus/7 Plus/8 Plus/X/XS/XS Max - portrait mode
'Default@2x~ipad~anyany': '[email protected]', // (2732x2732) - iPad Pro 12.9"/11"/10.5"/9.7"/7.9"
'Default@2x~ipad~comany': '[email protected]', // (1278x2732) - iPad Pro 12.9"/11"/10.5"/9.7"/7.9" - portrait mode
// Android
'android_universal': 'splash/android_universal.png', // (320x480)
});
// Set PhoneGap/Cordova preferences.
App.setPreference('BackgroundColor', '0xff0000ff');
App.setPreference('HideKeyboardFormAccessoryBar', true);
App.setPreference('Orientation', 'default');
App.setPreference('Orientation', 'all', 'ios');
// Pass preferences for a particular PhoneGap/Cordova plugin.
App.configurePlugin('com.phonegap.plugins.facebookconnect', {
APP_ID: '1234567890',
API_KEY: 'supersecretapikey'
});
// Add custom tags for a particular PhoneGap/Cordova plugin to the end of the
// generated config.xml. 'Universal Links' is shown as an example here.
App.appendToConfig(`
<universal-links>
<host name="localhost:3000" />
</universal-links>
`);
App.setPreference
摘要
根据Cordova 文档中所述,为您的构建添加首选项。
参数
源代码名称 | 类型 | 描述 | 必需 |
---|---|---|---|
name | 字符串 | Cordova 的 | 是 |
value | 字符串 | 该首选项的值。 | 是 |
platform | 字符串 | 可选。平台名称( | 否 |
App.setPreference(
"name",
"value",
"platform", // this param is optional
);
App.accessRule
摘要
根据源域为您的应用程序设置新的访问规则。默认情况下,您的应用程序可以联系的服务器列表有限。使用此方法扩展此列表。
默认访问规则
tel:*
、geo:*
、mailto:*
、sms:*
、market:*
是允许的,并由系统处理(例如,在电话应用程序或电子邮件客户端中打开)https://127.0.0.1:*
用于从服务器提供应用程序的资产。- 要连接以获取 DDP 和新版本热代码推送的 Meteor 服务器的域或地址。
在Cordova 文档中阅读有关域模式的更多信息。
从 Meteor 1.0.4 开始,由于某种可能的攻击,不再默认设置所有域和协议的访问规则(<access origin="*"/>
)。
参数
源代码名称 | 类型 | 描述 | 必需 |
---|---|---|---|
pattern | 字符串 | 定义受影响域或 URL 的模式。 | 是 |
选项 | 对象 | 否 |
App.accessRule(
"pattern",
options, // this param is optional
);
例如,此 Cordova 白名单语法
<access origin="https://127.0.0.1" />
<allow-navigation href="https://example.com" />
等效于
App.accessRule('https://127.0.0.1');
App.accessRule('https://example.com', { type: 'navigation' });
App.configurePlugin
摘要
设置 Cordova 插件的构建时配置。
参数
源代码名称 | 类型 | 描述 | 必需 |
---|---|---|---|
id | 字符串 | 要配置的插件的标识符。 | 是 |
config | 对象 | 一组键值对,将在构建时传递以配置指定的插件。 | 是 |
App.configurePlugin(
"id",
config,
);
注意:当使用
App.configurePlugin
重新配置先前已配置的插件时,如果未手动清除现有的 Cordova 构建,则更改可能不会反映出来。要清除现有的 Cordova 构建,请删除.meteor/local/cordova-build
目录,然后使用meteor run
或meteor build
重新构建应用程序。
App.icons
摘要
设置移动应用程序的图标。
参数
源代码名称 | 类型 | 描述 | 必需 |
---|---|---|---|
icons | 对象 | 一个对象,其中键是不同的设备和屏幕尺寸,值是相对于项目根目录的图像路径。 有效键值
| 是 |
App.icons(
icons
);
App.launchScreens
摘要
设置移动应用程序的启动屏幕图像。
参数
源代码名称 | 类型 | 描述 | 必需 |
---|---|---|---|
launchScreens | 对象 | 一个字典,其中键是不同的设备、屏幕尺寸和方向,值是相对于项目根目录的图像路径或包含深色模式图像路径的对象 有关 Android 的具体信息,请查看Cordova 文档和Android 文档。另请注意,对于 Android,资产可以是 XML 矢量可绘制对象或 PNG。 有关开发启动图像的最佳实践,请参阅Apple 指南。要了解有关 iOS 尺寸类的更多信息,请查看 Cordova 的文档。 有效键值 iOS
Android
| 是 |
App.launchScreens(
launchScreens
);
App.appendToConfig
摘要
将自定义标签附加到 config 的 widget 元素中。
App.appendToConfig('<any-xml-content/>');
参数
源代码名称 | 类型 | 描述 | 必需 |
---|---|---|---|
element | 字符串 | 要包含的 XML | 是 |
App.appendToConfig(
"element"
);
App.addResourceFile
摘要
根据Cordova 文档中所述,为您的构建添加资源文件。
参数
源代码名称 | 类型 | 描述 | 必需 |
---|---|---|---|
src | 字符串 | 项目资源路径。 | 是 |
target | 字符串 | 构建中的资源目标。 | 是 |
platform | 字符串 | 可选。平台名称( | 否 |
App.addResourceFile(
"src",
"target",
"platform", // this param is optional
);
注意:资源文件分两步复制:从 Meteor 项目的src复制到 Cordova 项目的根目录,然后复制到target