问题描述
我是流星的新手.我正在用流星开发移动应用程序.我需要在 config.xml 中添加 <access origin="*"/>
我正在使用 google API 在浏览器中工作正常.但是当我在 android 设备上运行时,控制台抛出 Uncaught ReferenceError: google is not defined
.我认为问题是cordova 阻止了google api.我应该如何添加来自meteor的访问源?
I am new to meteor. I am developing mobile app with meteor. I need to add <access origin="*"/>
in config.xml I am using google API works fine in browser. But when I run in android device, console throws Uncaught ReferenceError: google is not defined
. I think the problem is cordova blocks google api. How should I add access origin from meteor?
推荐答案
在您的根流星项目中创建一个 mobile-config.js 文件.阅读 https://docs.meteor.com/#/full/mobileconfigjs
Create a mobile-config.js file in your root meteor project. Read https://docs.meteor.com/#/full/mobileconfigjs
您可以像这样添加原始通配符.
You can add an origin wildcard like so.
App.accessRule('*');
这会将以下内容添加到您的 config.xml
This will add the following to your config.xml
<access origin="*"/>
以下来自:https://docs.meteor.com/#/full/App-accessRule
App.accessRule(domainRule, [options])
为您的应用设置基于源域的新访问规则.默认情况下您的应用程序可以联系的服务器列表有限.利用这个方法来扩展这个列表.
Set a new access rule based on origin domain for your app. By default your application has a limited list of servers it can contact. Use this method to extend this list.
默认访问规则:
- tel:、geo:、mailto:、sms:、market:* 允许并在外部启动(手机应用或 Android 上的电子邮件客户端)
- gap:, cdv:, file: 允许(访问本地文件系统所需的协议)http://meteor.local/* 是允许的(Meteor 使用的域
访问应用的资产) - 传递给构建过程的服务器的域名(或开发模式下的本地ip地址)用于可以联系
Meteor 应用服务器.
- tel:, geo:, mailto:, sms:, market:* are allowed and launch externally (phone app, or an email client on Android)
- gap:, cdv:, file: are allowed (protocols required to access local file-system) http://meteor.local/* is allowed (a domain Meteor uses
to access app's assets) - The domain of the server passed to the build process (or local ip address in the development mode) is used to be able to contact the
Meteor app server.
在 Cordova 文档中阅读有关域模式的更多信息.
Read more about domain patterns in Cordova docs.
从适用于所有域和协议的 Meteor 1.0.4 访问规则开始() 不再默认设置,因为 某些一种可能的攻击.
Starting with Meteor 1.0.4 access rule for all domains and protocols () is no longer set by default due to certain kind of possible attacks.
参数
domainRule 字符串 - 定义受影响的域或 URL 的模式.
domainRule String - The pattern defining affected domains or URLs.
选项
launchExternal 布尔值 - 如果匹配的 URL 应该在外部处理(例如 Android 上的手机应用或电子邮件客户端),则设置为 true.
launchExternal Boolean - Set to true if the matching URL should be handled externally (e.g. phone app or email client on Android).
这篇关于在流星应用程序中如何在cordova config.xml 中添加orgin=*?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!