Reputation: 658
I'm writing an app that sends requests to a REST API.
The API calls work in the web browser, but not in the emulator and not on a device.
Ionic CLI 4.4.0
Cordova 8.1.2
What i did:
I use android-permissions like on this side:
app.modules.ts
import { AndroidPermissions } from '@ionic-native/android-permissions';
@NgModule({
declarations: [
],
imports: [
],
entryComponents: [
],
providers: [
AndroidPermissions
],
bootstrap: [IonicApp]
})
export class AppModule {}
api-call.ts
import { AndroidPermissions } from '@ionic-native/android-permissions';
export class ApiCallPage {
constructor(private androidPermissions: AndroidPermissions) {
this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.INTERNET).then(
result => console.log('Has permission?', result.hasPermission),
err => this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.INTERNET)
);
}
}
The target device (device and emulator in AVD manager) has API 22 (Android 5.1).
config.xml
<access origin="*" />
<preference name="android-minSdkVersion" value="19" />
<plugin name="cordova-plugin-android-permissions" spec="1.0.0" />
<engine name="android" spec="^7.1.1" />
The last one (engine name) is probably for the cordova-android version and does not have to be 5.1. In package.json is under dependencies "cordova-android": "^7.1.1"
.
...both files includes (not written by hand):
<uses-permission android:name="android.permission.INTERNET" />
It is not a CORS problem. The REST API runs on a different server than the web browser and it works with the web browser.
I think I did everything. Is something missing or wrong?
What do you have to do to have Ionic (cordova) Internet access?
[UPDATE] The app info shows me the permissions that the app has full network access. Now I'm at a loss.
In the API, I log every request at boot time. A request of the app from the device does not arrive. The app in the browser arrives.
Upvotes: 1
Views: 4139
Reputation: 658
It was a CORS issue, but not on the API side, but on the client side.
In the config.xml <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
solves my problem.
Take a look at github ionic-team issue
For me it was Android 5.1 & 8.0.
Upvotes: 1