Reputation: 127
Not exactly sure how to put this but Meteor.call and .methods are not working when building the app on the mobile specifically on iOS although I haven't tried yet on Android. On my previous project, this doesn't happen. I tried comparing with the other app and, actually, I reused the other for this new app but it just doesn't work. Also, everything works perfectly fine on both web and iOS simulator. Someone please help.
imports/startup/server/methods.js
import { HTTP } from 'meteor/http';
import { Meteor } from 'meteor/meteor';
Meteor.methods({
methodTrial: function(data) {
console.log("Called methodTrial");
return false;
}
});
imports/startup/ui/pages/home.js
import './home.html';
import { Meteor } from 'meteor/meteor';
Template.payment.events({
"click #test-method": (event) => {
var data = {
name : "Hello World"
};
Meteor.call('methodTrial', data, (error, result) => {
console.log("Called 'methodTrial'");
}
}
});
imports/startup/server/index.js
import './methods.js';
server/main.js
import { Meteor } from 'meteor/meteor';
import '/imports/startup/server';
Upvotes: 0
Views: 393
Reputation: 53350
Your 'methodTrial'
Meteor method is server only.
Therefore your client does not run any stub / simulation of that method, and purely relies on the server response to give the user any feedback.
If for any reason the device cannot connect to your server, the client will not be able to trigger the method on the server, and it will never receive any response.
A common misconception during development is that because your device (whether iOS or Android based) is wired to your computer (through USB data cable), it is connected to your server. But actually this is only true for app deployment (when you execute meteor run ios-device
or meteor run android-device
). Once the app is installed and open, it needs to connect to your computer local server through your WiFi network.
See the Meteor Guide > Build > Mobile > Developing on a mobile:
During development, […] the device and the computer you run
meteor
on will have to be part of the same WiFi network, and the network configuration shouldn’t prevent the device from reaching the server. You may have to change your firewall or router settings to allow for this (no client isolation).
meteor run
will try to detect the local IP address of the computer running the command automatically. If this fails, or if you would like your mobile app to connect to a different server, you can specify an address using the--mobile-server
option.
Common mistakes are:
Upvotes: 0