I have a button when pressing it performs the request for some data. So, in my ts file of the page where the button is, I call the function in my provider.
The main problem comes when I compile my application for android platform (Generate apk with ionic cordova build --release android, then I Sign the apk, align and install it). In that case, when I press the button nothing happens, I debugged the code (I added some alerts), but only the first line of the function (The alert that I added) is executed, never returns anything.
But… If I run the app with the commands: ionic cordova run android -l and ionic serve -l. It works like a charm (The provider return the data requested)
I mean, the problem is only when I generate the APK to install it into my device
I also tried with HttpClient but the problem persists.
The code of my Provider is:
Search(path): Promise<any> {
// ------------- The alert is shown
return this.http.get(path)
.map(res => res.json())
.toPromise()
.then(
response => {
// ------------- The alert is not shown
if (typeof response.user.name !== "undefined") {
this.storage.set('users', JSON.stringify(response));
return response;
} else {
return null;
}
},
error => {
// ------------- The alert is not shown
return null;
});
}
I also tried with something like this:
Search(path): Promise<any> {
// ------------- The alert is shown
return null;
}
But, also in this case the return line is never executed, only the alert is shown.
The code when I call my provider function in the page where the button is:
this.APIService.Search(final_path).then(res => {
if (res) {
this.storage.get('users').then(responseJson => {
if (responseJson) {
this.navCtrl.push(ObtenerPage);
}
});
} else {
this.presentToast("Bad request");
}
});