Ionic native Http post not working in IOS - ionic-framework

I need help in resolving this issue. I’m facing issue when doing POST request to get the access token in IOS. Whereas it works fine in Android.
I'm using the Cordova plugin cordova-plugin-advanced-http: "^2.4.1".
Code:
const bodyParams = {‘client_id’:clientId,‘client_secret’:secret,‘grant_type’:‘authorization_code’,‘code’:tokenOrCode};
const httpResponse = await this.http.post(accessTokenUrl, bodyParams, {“Content-Type”: “application/json”});
Error:
{“error”:“invalid_client”,“error_description”:“FBTOAU204E An invalid secret was provided for the client with identifier: ‘abc#abc.com’.”}
Note: The above code works without any issues in Android.
Package.json:
"#angular/common": "^7.2.2",
"#angular/core": "^7.2.2",
"#angular/forms": "^7.2.2",
"#angular/http": "^7.2.2",
"#angular/platform-browser": "^7.2.2",
"#angular/platform-browser-dynamic": "^7.2.2",
"#angular/router": "^7.2.2",
"#ionic-native/core": "^5.0.0",
"#ionic-native/http": "^5.2.0",
"#ionic-native/network": "^5.24.0",
"#ionic-native/secure-storage": "^5.2.0",
"#ionic-native/splash-screen": "^5.0.0",
"#ionic-native/status-bar": "^5.0.0",
"#ionic/angular": "^4.1.0",
"ajv": "^6.10.0",
"cordova-ios": "^4.5.5",
"cordova-plugin-advanced-http": "^2.0.9",
"cordova-plugin-cookiemaster": "^1.0.5",
"cordova-plugin-device": "^2.0.3",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-ionic-keyboard": "^2.2.0",
"cordova-plugin-ionic-webview": "^3.0.0",
"cordova-plugin-network-information": "^2.0.2",
"cordova-plugin-secure-storage": "^3.0.2",
"cordova-plugin-splashscreen": "^5.0.3",
"cordova-plugin-statusbar": "^2.4.3",
"cordova-plugin-whitelist": "^1.3.4",
"core-js": "^2.5.4",
"rxjs": "~6.3.3",
"zone.js": "~0.8.29"

Before sending post request set serializer as per your request :
For json :
this.http.setDataSerializer("json");
const bodyParams = {‘client_id’:clientId,‘client_secret’:secret,‘grant_type’:‘authorization_code’,‘code’:tokenOrCode};
const httpResponse = await this.http.post(accessTokenUrl, bodyParams, {“Content-Type”: “application/json”});

I was having a problem similar to your problem like request was working on Android, was not working on Ios. (Ionic 5 - Capacitor App)
I fixed my problem to changing my content-type.
It may help you too, please try it.
{“Content-Type”: “application/json”}
Replace with the following
{“Content-Type”: “application/x-www-form-urlencoded”}

Related

ERROR in The target entry-point "ngx-restangular" has missing dependencies: core-js/features/object

When i start 'ionic serve' i have this issue
[ng] ERROR in The target entry-point "ngx-restangular" has missing dependencies:
[ng] - core-js/features/object
And the app don't show in browser.
My Package.json
"dependencies": {
"#angular/common": "~9.0.7",
"#angular/core": "~9.0.7",
"#angular/forms": "~9.0.7",
"#angular/platform-browser": "~9.0.7",
"#angular/platform-browser-dynamic": "~9.0.7",
"#angular/router": "~9.0.7",
"#ionic-native/core": "^5.0.7",
"#ionic-native/geolocation": "^5.27.0",
"#ionic-native/in-app-browser": "^5.35.0",
"#ionic-native/native-geocoder": "^5.27.0",
"#ionic-native/splash-screen": "^5.0.0",
"#ionic-native/status-bar": "^5.0.0",
"#ionic/angular": "^5.0.0",
"cordova-android": "~7.0.0",
"cordova-ios": "^5.1.1",
"cordova-plugin-add-swift-support": "^2.0.2",
"cordova-plugin-geolocation": "^4.1.0",
"cordova-plugin-nativegeocoder": "^3.4.1",
"ngx-permissions": "^8.1.1",
"ngx-restangular": "^5.0.0",
"rxjs": "~6.5.4",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.901.5",
"#angular/cli": "9.1.15",
"#angular/compiler": "~9.0.7",
"#angular/compiler-cli": "~9.0.7",
"#angular/language-service": "~9.0.7",
"#ionic/angular-toolkit": "^2.1.1",
"#types/jasmine": "~3.5.0",
"#types/jasminewd2": "~2.0.3",
"#types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-ionic-keyboard": "^2.2.0",
"cordova-plugin-ionic-webview": "^4.2.1",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-whitelist": "^1.3.3",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~5.0.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.0",
"karma-jasmine": "~3.0.1",
"karma-jasmine-html-reporter": "^1.4.2",
"moment": "^2.29.1",
"protractor": "~5.4.3",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~3.7.3"
},
Help please
I ran
npm i core-js --legacy-peer-deps
and my problem was solved

Ionic 3 google maps link generated in the head

I'm working on an offline app with ionic version 3 but something strange always happens when i run "ionic cordova run android"
In the index.html in head it generates this :
<!-- cordova.js required for cordova apps (remove if not needed) -->
<script src="https://maps.googleapis.com/maps/api/js?key=xxx"></script>
<script src="cordova.js"></script>
I removed all the plugins and modules for gps and maps
this is my package.json file:
"dependencies": {
"#angular/platform-browser": "5.2.11",
"#angular/platform-browser-dynamic": "5.2.11",
"#ionic-native/aes-256": "^4.20.0",
"#ionic-native/android-permissions": "^4.20.0",
"#ionic-native/app-update": "^4.20.0",
"#ionic-native/app-version": "^4.20.0",
"#ionic-native/barcode-scanner": "^4.20.0",
"#ionic-native/bluetooth-serial": "^4.20.0",
"#ionic-native/core": "~4.18.0",
"#ionic-native/device": "^4.20.0",
"#ionic-native/diagnostic": "^4.19.0",
"#ionic/storage": "^2.2.0",
"cordova-android": "8.1.0",
"cordova-plugin-advanced-http": "^2.1.1",
"cordova-plugin-aes256-encryption": "^1.2.2",
"cordova-plugin-android-permissions": "^1.0.0",
"cordova-plugin-app-update": "^2.0.2",
"cordova-plugin-app-version": "^0.1.9",
"cordova-plugin-appversion": "^1.0.0",
"cordova-plugin-bluetooth-serial": "0.4.7",
"cordova-plugin-dbcopy": "^2.1.2",
"cordova-plugin-device": "^2.0.3",
"cordova-plugin-email-composer": "^0.9.2",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-ionic-keyboard": "^2.1.3",
"cordova-plugin-ionic-webview": "^2.5.1",
"cordova-plugin-network-information": "^2.0.2",
"cordova-plugin-permission": "0.1.0",
"cordova-plugin-splashscreen": "^5.0.3",
"cordova-plugin-statusbar": "^2.4.3",
"cordova-plugin-uid": "^1.3.0",
"cordova-plugin-uniquedeviceid": "^1.3.2",
"cordova-plugin-whitelist": "^1.3.4",
"cordova-plugin-x-toast": "^2.7.2",
"cordova-sqlite-storage": "^3.2.1",
"cordova.plugins.diagnostic": "^4.0.12",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"rxjs": "5.5.11",
"sw-toolbox": "3.6.0",
"ts-md5": "^1.2.4",
"zone.js": "0.8.26"
},
I don't need maps anyways so any help would be appreciated !
There is probably still plugins defined in your Cordova config.xml file.
Or alternatively remove the plugins with Cordova command
cordova plugin remove <plugin>
or
cordova plugin rm <plugin>

Error: “Unresolved function or method present()” when using LoadingController

ISSUE:
When I use the LoadingController in my project, I see the following error: "Unresolved function or method present()"
Here is the screenshot code that I have in my file:
As we can see from the screenshot, there are 2 pieces of code that show the same error. The code from lines: 51-61 are a direct copy of the code from the ionic documentation that can be seen under Usage
The code from lines: 63-69 are the trimmed down and basic version of the code and for testing purposes await is removed in front of the loading.present();. Yet it throws the same error as the original code above.
GOAL:
What can we do to fix the issue so that Intellij Idea (IDE) stops complaining about the same?
Following is the info from my package.json:
{
"name": "gf",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/common": "~8.1.2",
"#angular/compiler": "~8.1.2",
"#angular/core": "~8.1.2",
"#angular/forms": "~8.1.2",
"#angular/platform-browser": "~8.1.2",
"#angular/platform-browser-dynamic": "~8.1.2",
"#angular/router": "~8.1.2",
"#ionic-native/core": "^5.0.0",
"#ionic-native/splash-screen": "^5.0.0",
"#ionic-native/status-bar": "^5.0.0",
"#ionic/angular": "^4.7.1",
"#ionic/storage": "^2.2.0",
"cordova-sqlite-storage": "^3.2.1",
"core-js": "^2.5.4",
"rxjs": "~6.5.1",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"#angular-devkit/architect": "~0.801.2",
"#angular-devkit/build-angular": "~0.801.2",
"#angular-devkit/core": "~8.1.2",
"#angular-devkit/schematics": "~8.1.2",
"#angular/cli": "~8.1.2",
"#angular/compiler": "~8.1.2",
"#angular/compiler-cli": "~8.1.2",
"#angular/language-service": "~8.1.2",
"#ionic/angular-toolkit": "~2.0.0",
"#types/jasmine": "~3.3.8",
"#types/jasminewd2": "~2.0.3",
"#types/node": "~8.9.4",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.4.3"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-sqlite-storage": {}
}
}
}
No sure it is the right way to do it but i managed to Intellij to stop whining
return (<any>loading).present();

RxJS module give error after update. how to solve?

In my angular 5 project. My imports have been producing weird errors that I cant remember having a few days ago. For the import here below it says: "module ...rxjs/observable has no exported member observable".
import { Observable } from 'rxjs/Observable';
I did not have this before.
Funny thing is however, the angular website, including the functionality with the observable, works just fine
Here is my package.json:
"private": true,
"dependencies": {
"#angular-devkit/core": "0.0.29",
"#angular/animations": "^5.2.0",
"#angular/cdk": "^5.2.5",
"#angular/common": "^5.2.0",
"#angular/compiler": "^5.2.0",
"#angular/core": "^5.2.0",
"#angular/forms": "^5.2.0",
"#angular/material": "^5.2.0",
"#angular/material-moment-adapter": "^5.2.5",
"#angular/platform-browser": "^5.2.0",
"#angular/platform-browser-dynamic": "^5.2.0",
"#angular/router": "^5.2.0",
"bootstrap": "^4.0.0",
"core-js": "^2.4.1",
"jsonwebtoken": "^8.2.0",
"moment": "^2.20.1",
"moment-duration-format": "^2.2.2",
"npm": "^5.6.0",
"rxjs": "^5.5.12",
"zone.js": "^0.8.19"
},
Unfortunately, I do not know how to solve the import problem. However, I think it might be worth mentioning that I experienced a similar issue when updating to the latest version for Angular 6, that is to say rxjs 6.3.0. So I downgraded to 6.2.1, which made the import errors go away.

How to stop ionic cordova run android command delete existing ionic apps on the device

I'm new to the forum and need help on running/installing ionic 3 app on a real device.
This command: ionic cordova run android (in my case) will delete the existing ionic app being installed on the device even though the app names are different.
I'd tried using ionic cordova run android --prod --release but the result is the same, i.e. Only ONE ionic app will be installed on the Android device which doesn't sound right.
Is there a way to prevent that from happening? Any options? Below is my package.json file:
"dependencies": {
"#angular/common": "5.0.3",
"#angular/compiler": "5.0.3",
"#angular/compiler-cli": "5.0.3",
"#angular/core": "5.0.3",
"#angular/forms": "5.0.3",
"#angular/http": "5.0.3",
"#angular/platform-browser": "5.0.3",
"#angular/platform-browser-dynamic": "5.0.3",
"#ionic-native/core": "4.4.0",
"#ionic-native/splash-screen": "4.4.0",
"#ionic-native/status-bar": "4.4.0",
"#ionic/pro": "1.0.16",
"#ionic/storage": "2.1.3",
"cordova-android": "6.3.0",
"cordova-plugin-device": "^1.1.4",
"cordova-plugin-ionic-webview": "^1.1.16",
"cordova-plugin-splashscreen": "^4.0.3",
"cordova-plugin-whitelist": "^1.3.1",
"ionic-angular": "3.9.2",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "3.0.0",
"rxjs": "5.5.2",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.18"
},
Have you changed the package name of that App? This issue happened when package name of Apps are same.