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';
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-deviceormeteor 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:
Common mistakes are: