我正在尝试使用Ionic
登录,它可以在浏览器上运行,但是当我在android设备上运行应用程序时,该应用程序无法正常工作。
所以我有以下LoginController
(function(){
'use strict';
app.controller('LoginController', ['$scope','$ionicLoading','LoginService','$state','localStorageService',
function($scope,$ionicLoading,LoginService,$state,localStorageService)
{
$scope.title= 'Control de Rondas';
$scope.spinner = false;
$scope.renderError = false;
$scope.data = false;
$scope.pin = undefined;
/**
* Función que se encarga de llamar el servicio de login
* @param pin Pin del usuario a logearse.
*
*/
$scope.login = function(pin)
{
$scope.pin = pin;
$ionicLoading.show({template: 'Cargando...' });
var login = new LoginService();
console.debug('antes de enatrar');
login.callService(pin).then(function()
{
console.log("here never entered...");
$scope.data = login.getData();
if($scope.data){
localStorageService.set( 'pin', $scope.pin );
$state.go('operador');
}
else{
$scope.renderError = true;
}
$ionicLoading.hide();
},
function(error){
console.log("error");
console.log( JSON.stringify(error));
}
);
};
}//end function.
]);//close the controller.
})();
我建立了一个服务来调用Soap客户登录
'use strict';
/**
* Servicio que permite hacer llamado al web service para logearse en la
* aplicación.
*
* @author Cristian Chaparro Africano.
*/
app.factory('LoginService', ['SoapClient',function(SoapClient){
function LoginService(){
this.data = [];
}
/**
* Funcion para consumir el servicio de login.
* @param pin del operador a logear.
*/
LoginService.prototype.callService = function(pin){
var url = 'http://cooldomain.com/web/app_dev.php/ws/loginOperador?wsdl';
var soapMessage =
'<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><login xmlns="http://cooldomain.com/ws/loginOperador/1.0/"><pin>' +
pin + '</pin></login></soap:Body></soap:Envelope>';
var soap = new SoapClient(url,soapMessage);
var promise = soap.callService();
var self = this;
promise.then(function(d){
self.data = d;
});
return promise;
};
/**
* Funcion que obtiene la informacion que retorna el web service y la procesa.
*
* @return String con la respuesta de acceso
*/
LoginService.prototype.getData = function(){
var result = this.data.data;
var res = '<return>';
var inicio = result.indexOf(res);
var fin = result.indexOf('</return>');
this.data = result.substring(inicio+res.length,fin);
return ((this.data === 'allow-op') ? true : false);
};
return LoginService;
}]);
这是我的SoapClient:
app.factory('SoapClient',['$http',function($http) {
function SoapClient(url,soapMessage){
this.url = url;
this.soapMessage = soapMessage;
this.data = '';
}
SoapClient.prototype.callService = function(){
var promise = $http({
url: this.url,
method: 'POST',
data: this.soapMessage
});
return promise;
};
return SoapClient;
}]);
当我在android设备上运行应用程序时,在控制台上出现以下错误
I/Web Console( 6061): {"data":null,"status":0,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"url":"http://cooldomain.co/controlid/web/app_dev.php/ws/loginOperador?wsdl","data":"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><login xmlns=\"http://cooldomain.co/ws/loginOperador/1.0/\"><pin>18485</pin></login></soap:Body></soap:Envelope>","headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json;charset=utf-8"}},"statusText":""}
我该如何解决这个问题?
最佳答案
如果您使用的是最新的Cordova版本(即5.0.0),则需要添加新的cordova-plugin-whitelist,否则网络请求将被阻止:
ionic plugin add cordova-plugin-whitelist