【问题标题】:Meteor Mobile App cannot connect to serverMeteor Mobile App 无法连接到服务器
【发布时间】:2016-12-15 13:10:05
【问题描述】:

我在使用 android、ios 和 iOS 模拟器连接到我的服务器时遇到了一系列问题。经过几天的反复寻找解决此问题的方法。我每次都走得更近,但仍然无法完全连接。我有 Iron:Router,可以访问任何不需要登录的页面,但是一旦我尝试注册或登录,它就会“冻结”,并且在调试过程中它说它无法连接。

已尝试

1。具体 DDP_DEFAULT_CONNECTION

在 /server/lib/config.js 中

Meteor.startup(function() {

    var theURL = "http://myUrl.com:3000";

    if (process.env.NODE_ENV === "development") {
        theURL = "http://101.ipaddress.0.0:3000";
    }

    Meteor.absoluteUrl.defaultOptions.rootUrl = theURL;
    process.env.ROOT_URL = theURL;
    process.env.MOBILE_ROOT_URL = theURL;
    process.env.MOBILE_DDP_URL = theURL;
    process.env.DDP_DEFAULT_CONNECTION_URL = theURL;

});

在对这些进行了一些修改之后,它随后将我转达给了一个 CORS 问题。我通过这样做解决了

2。 CORS 和 App.access

在 mobile-config.js 中

App.accessRule('http://*');
App.accessRule('https://*');

然后这给我带来了另一个与 iOS 安全传输相关的错误,我相信它是从 xcode 8 更新的?我解决了这个问题

3。更改应用传输安全设置

在 xCode 的 info 选项卡中:在 App Transport Security 下添加了“Allow Arbitrary Loads”:“true”

建议步骤

我还发现了一个不错的小块,可以控制日志连接状态。

if(Meteor.isClient){
  Meteor.autorun(function () {
    var stat;
    if (Meteor.status().status === "connected") {
        stat = 'lime'
    }else if (Meteor.status().status === "connecting") {
        stat = 'yellow'
    }else {
        stat = 'red';
    }
    Session.set('status',stat);
  });
}
        
console.log(Session.get('status'));

这与注册按钮相关联,每次单击它都会触发状态。它一直是“红色的”。

Safari 调试器说我无法连接。

连接步骤

meteor run ios-device --mobile-server 101.ipaddress:3000

然后我点击运行按钮。我已阅读热代码推送问题,通常会删除 '.meteor/local/bundler-cache' && 'cordova-build'

我遇到了障碍,希望得到一些关于下一个解决方案的帮助/建议(或者我可能从根本上跳过了一些同时会非常烦人但又很快乐的事情)。

额外信息

Meteor 版本已尝试 1.2.1 和 1.3 mup.json

{
  // Server authentication info
  "servers": [
    {
      "host": "101.ipaddress.0.1",
      "username": "username",
      //"password": "password",
      // or pem file (ssh based authentication)
      // WARNING: Keys protected by a passphrase are not supported
      "pem": "ssh/directory",
      "pem": "ssh/directory",
      "env": {}
    }
  ],

  // Install MongoDB on the server. Does not destroy the local MongoDB on future setups
  "setupMongo": true,

  // Application name (no spaces).
  "appName": "AppName",

  // Location of app (local directory). This can reference '~' as the users home directory.
  // i.e., "app": "~/Meteor/my-app",
  // This is the same as the line below.
  "app": "/directory/to/app",

  // Configure environment
  // ROOT_URL must be set to your correct domain (https or http)
  "env": {
    "PORT": 80,
    "ROOT_URL": "http://domainNameURL.com",
    "MOBILE_ROOT_URL": "http://domainNameURL.com"
  },

  // Meteor Up checks if the app comes online just after the deployment.
  // Before mup checks that, it will wait for the number of seconds configured below.
  "deployCheckWaitTime": 60,

  // show a progress bar while uploading. 
  // Make it false when you deploy using a CI box.
  "enableUploadProgressBar": true
}

【问题讨论】:

  • 您无法发出 http 请求?
  • 我无法使用移动设备或其各自的模拟器“注册”或“登录”。我可以在浏览器上这样做。所以我认为这是一个 DDP 连接问题。

标签: android ios cordova meteor mobile


【解决方案1】:

虽然我的回答可能无法解决您问题的根源,但希望在调试过程中对您有所帮助。

显示当前连接状态的 postet sn-p 不是响应式的。 console.log(Session.get('status')); 不在反应式上下文中,这意味着它不会随着 Session 变量的变化而更新。这就是为什么它只记录初始值red。 将代码更改为以下内容以使其具有反应性:

if(Meteor.isClient){
  Meteor.autorun(function () {
    var stat;
    if (Meteor.status().status === "connected") {
        stat = 'lime'
    }else if (Meteor.status().status === "connecting") {
        stat = 'yellow'
    }else {
        stat = 'red';
    }
    console.log('status', stat);
  });
}

【讨论】:

  • 感谢您的提醒。我已将代码放在模板事件中,因此您没有上下文。另外,由于某种原因,新版本的流星 1.2.1 能够连接,所以我一次添加 4 个包,看看哪个包可能导致我最初猜测是铁路由器的问题,但这似乎没有就是这样。
【解决方案2】:

我无法在使用 1.2.1 版的新版本上复制错误。

但是可能是什么导致了一些问题:

[ip]:[port] 并不是我实际测试连接的方式。对我来说,构建应用程序并让它在设备和模拟器上运行的最成功的方法是

meteor build <directory> ios --mobile-server <ipaddress>

请注意 [port] 的缺失。

当我为苹果构建时,我使用

meteor run ios-device --mobile-server 101.ipaddress.1

然后点击产品>存档

对于部署,我使用 mupx mupx 部署

Meteor 的部署/编译过程可能是一团糟,因为我第一次尝试上传 apk 它给了我我在 mobile-config.js 中设置的实际数字,即版本 0.0.7,但之后每次尝试连接一个 8在末尾。即,如果我有 0.0.1 则为 18,而 0.0.2 则为 28。即使使用

App.setPreference('android-versionCode', '7');
App.setPreference('android-targetSdkVersion', '23')

设置。这是令人失望的,因为它似乎是 Web 应用程序的快速构建。我很高兴在移动设备上对其进行测试,遇到了这么多问题。

总之。构建了一个新的流星 1.2 应用程序。然后手动添加我所有的包。之后,我复制并粘贴了我的客户端、lib 和服务器文件夹。我现在可以注册和登录,它使用上面的编码 sn-p 显示一个活动连接。

【讨论】:

  • 嗨 Cody,meteor build ios --mobile-server 没有给你错误?我收到错误--mobile-server is not valid parameter.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-28
  • 1970-01-01
相关资源
最近更新 更多