跳至内容

移动配置

如果您的 Meteor 应用程序面向 iOS 或 Android 等移动平台,您可以在一个名为 mobile-config.js 的特殊顶级文件中配置应用程序的元数据和构建过程,该文件包含在您的应用程序中,仅用于此配置。

以下代码片段是一个 mobile-config.js 文件示例。本节的其余部分将更详细地解释具体的 API 命令。

js
// 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.info

摘要

设置移动应用程序的核心配置信息。

参数

源代码
名称类型描述必需
选项对象

选项

名称类型描述必需
id、version、name、description、author、email、website字符串

每个选项都对应于应用程序核心配置中的一个键,如Cordova 文档中所述。

js



const result = App.info();
  options
);

App.setPreference

摘要

根据Cordova 文档中所述,为您的构建添加首选项。

参数

源代码
名称类型描述必需
name字符串

Cordova 的 config.xml 支持的首选项名称。

value字符串

该首选项的值。

platform字符串

可选。平台名称(iosandroid),用于添加特定于平台的首选项。

js



const result = 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 的模式。

选项对象

选项

名称类型描述必需
type字符串

可能的值

  • 'intent':控制应用程序允许请求系统打开哪些 URL。(例如,在电话应用程序或电子邮件客户端中)。
  • 'navigation':控制 WebView 本身可以导航到的 URL(对于 iframe 也可能需要)。
  • 'network' 或未定义:控制允许进行哪些网络请求(图像、XHR 等)。
launchExternal布尔值

(已弃用,请改用 type: 'intent')。

js



const result = App.accessRule();
  "pattern",
options, // this param is optional
);

例如,此 Cordova 白名单语法

xml
<access origin="https://127.0.0.1" />
<allow-navigation href="https://example.com" />

等效于

js
App.accessRule('https://127.0.0.1');
App.accessRule('https://example.com', { type: 'navigation' });

App.configurePlugin

摘要

设置 Cordova 插件的构建时配置。

参数

源代码
名称类型描述必需
id字符串

要配置的插件的标识符。

config对象

一组键值对,将在构建时传递以配置指定的插件。

js



const result = App.configurePlugin();
  "id",
config,
);

注意:当使用 App.configurePlugin 重新配置先前已配置的插件时,如果未手动清除现有的 Cordova 构建,则更改可能不会反映出来。要清除现有的 Cordova 构建,请删除 .meteor/local/cordova-build 目录,然后使用 meteor runmeteor build 重新构建应用程序。

App.icons

摘要

设置移动应用程序的图标。

参数

源代码
名称类型描述必需
icons对象

一个对象,其中键是不同的设备和屏幕尺寸,值是相对于项目根目录的图像路径。

有效键值

  • app_store (1024x1024) // Apple App Store
  • iphone_2x (120x120) // iPhone 5、SE、6、6s、7、8
  • iphone_3x (180x180) // iPhone 6 Plus、6s Plus、7 Plus、8 Plus、X
  • ipad_2x (152x152) // iPad、iPad mini
  • ipad_pro (167x167) // iPad Pro
  • ios_settings_2x (58x58) // iPhone 5、SE、6、6s、7、8、iPad、mini、Pro
  • ios_settings_3x (87x87) // iPhone 6 Plus、6s Plus、7 Plus、8 Plus、X
  • ios_spotlight_2x (80x80) // iPhone 5、SE、6、6s、7、8、iPad、mini、Pro
  • ios_spotlight_3x (120x120) // iPhone 6 Plus、6s Plus、7 Plus、8 Plus、X
  • ios_notification_2x (40x40) // iPhone 5、SE、6、6s、7、8、iPad、mini、Pro
  • ios_notification_3x (60x60 // iPhone 6 Plus、6s Plus、7 Plus、8 Plus、X
  • ipad (76x76) // 遗留
  • ios_settings (29x29) // 遗留
  • ios_spotlight (40x40) // 遗留
  • ios_notification (20x20) // 遗留
  • iphone_legacy (57x57) // 遗留
  • iphone_legacy_2x (114x114) // 遗留
  • ipad_spotlight_legacy (50x50) // 遗留
  • ipad_spotlight_legacy_2x (100x100) // 遗留
  • ipad_app_legacy (72x72) // 遗留
  • ipad_app_legacy_2x (144x144) // 遗留
  • android_mdpi (48x48)
  • android_hdpi (72x72)
  • android_xhdpi (96x96)
  • android_xxhdpi (144x144)
  • android_xxxhdpi (192x192)
js



const result = App.icons();
  icons
);

App.launchScreens

摘要

设置移动应用程序的启动屏幕图像。

参数

源代码
名称类型描述必需
launchScreens对象

一个字典,其中键是不同的设备、屏幕尺寸和方向,值是相对于项目根目录的图像路径或包含深色模式图像路径的对象 { src, srcDarkMode }(仅限 iOS)。注意:如果要在 Android 上使用深色主题启动屏幕,请按照此处所述的说明进行操作。

有关 Android 的具体信息,请查看Cordova 文档Android 文档。另请注意,对于 Android,资产可以是 XML 矢量可绘制对象或 PNG。

有关开发启动图像的最佳实践,请参阅Apple 指南。要了解有关 iOS 尺寸类的更多信息,请查看 Cordova 的文档

有效键值

iOS

  • ios_universal ([email protected] - 2732x2732 px) - 所有 @2x 设备,如果未声明设备/模式特定
  • ios_universal_3x ([email protected] - 2208x2208 px) - 所有 @3x 设备,如果未声明设备/模式特定
  • Default@2x~universal~comany (1278x2732 px) - 所有 @2x 设备(纵向模式)
  • Default@2x~universal~comcom (1334x750 px) - 所有 @2x 设备(横向(窄)模式)
  • Default@3x~universal~anycom (2208x1242 px) - 所有 @3x 设备(横向(宽)模式)
  • Default@3x~universal~comany (1242x2208 px) - 所有 @3x 设备(纵向模式)
  • Default@2x~iphone~anyany (1334x1334 px) - iPhone SE/6s/7/8/XR
  • Default@2x~iphone~comany (750x1334 px) - iPhone SE/6s/7/8/XR - 纵向模式
  • Default@2x~iphone~comcom (1334x750 px) - iPhone SE/6s/7/8/XR - 横向(窄)模式
  • Default@3x~iphone~anyany (2208x2208 px) - iPhone 6s Plus/7 Plus/8 Plus/X/XS/XS Max
  • Default@3x~iphone~anycom (2208x1242 px) - iPhone 6s Plus/7 Plus/8 Plus/X/XS/XS Max - 横向(宽)模式
  • Default@3x~iphone~comany (1242x2208 px) - iPhone 6s Plus/7 Plus/8 Plus/X/XS/XS Max - 纵向模式
  • Default@2x~ipad~anyany (2732x2732 px) - iPad Pro 12.9"/11"/10.5"/9.7"/7.9"
  • Default@2x~ipad~comany (1278x2732 px) - iPad Pro 12.9"/11"/10.5"/9.7"/7.9" - 纵向模式

Android

  • android_universal (288x288 dp)
js



const result = App.launchScreens();
  launchScreens
);

App.appendToConfig

摘要

将自定义标签附加到 config 的 widget 元素中。

App.appendToConfig('<any-xml-content/>');

参数

源代码
名称类型描述必需
element字符串

要包含的 XML

js



const result = App.appendToConfig();
  "element"
);

App.addResourceFile

摘要

根据Cordova 文档中所述,为您的构建添加资源文件。

参数

源代码
名称类型描述必需
src字符串

项目资源路径。

target字符串

构建中的资源目标。

platform字符串

可选。平台名称(iosandroid,如果省略则为两者),用于添加资源文件条目。

js



const result = App.addResourceFile();
  "src",
"target",

"platform", // this param is optional
);

注意:资源文件分两步复制:从 Meteor 项目的src复制到 Cordova 项目的根目录,然后复制到target