$ ionic cordova plugin add cordova-plugin-http
$ npm install --save #ionic-native/http
The implementation is:
constructor(private https: HTTP ) {
}
this.https.get('http://ionic.io', {}, {})
.then(data => {
this.httpData =data;
console.log(data.status);
})
.catch(error => {
console.log(error.status);
});
And I get this error:
[20:49:03] console.warn: Native: tried calling HTTP.get, but the HTTP plugin is not installed.
[20:49:03] console.warn: Install the HTTP plugin: 'ionic plugin add cordova-plugin-http'
If you do not want to modify the ionic-native plugin like suggested by #alpere or if the solution does not work you can always use the cordova plugin without ionic-native. To do so tell typescript that the http handle exists by adding the following somewhere below your imports:
declare var http;
And then use it like this:
http.get(
'https://ionic.io/',
{},
{},
response => {
console.log(response.status);
},
response => {
console.error(response.error);
},
);
Note that there is no need of this because cordova plugins are defined on a global scope. The downside of using plugins without the ionic-native wrapper is that you loose the nice type annotations, promise callbacks and in some cases you will have to trigger angular change-detection yourself.
The Ionic Native HTTP changed the cordova plugin they are using since the old one hasn't been updated for a while. During the change the reference to the plugin has't been updated so it's broken.
(See: https://github.com/silkimen/cordova-plugin-advanced-http/issues/8)
You can fix it by changing the old referenced plugin to new one:
(After the commit also updating the plugin will fix the issue)
in #ionic-native/plugins/http/index.ts:
change:
pluginRef: 'cordovaHTTP',
to:
pluginRef: 'cordova.plugin.http',
See commit:
https://github.com/ionic-team/ionic-native/commit/49ee0d85a304770a9a3bd3e04eb9609e6d565b67
It may be caused by any of these three issues:
The plugin is not installed;
You ran the code on a browser (or other limited environment); or
The platform is not ready (You called your code before the plugin was loaded).
The master branch of ionic already fixed pluginRef: 'cordova.plugin.http',
problem,
Still if the problem persists or you don't want to change the source files try these steps, it worked for me.
remove existing builds
rm -rf node_modules/ platforms/ plugins/ www/
update ionic native to latest build :
npm i --save ionic-native#latest
(please check with other plugin dependencies as well if its a problem try isolating packages via virtual environment setup - https://github.com/ekalinin/nodeenv ) :
add all your plugins required and http plugin ::
ionic cordova plugin add cordova-plugin-advanced-http
Then finally your plugins required and http plugin
npm install #ionic-native/http
Now your upon builds iOS or android should detect all the plugins
Ionic3 Cordova SSL pinning example
https://github.com/sijovijayan/SSL-pinning-with-ionic-cordova-example
In this example, you will get an idea about how implement SSL Pinning and How to Generate .cer file
try to run below command as suggested in error message to install HTTP plugin
ionic plugin add cordova-plugin-http
I would switch to Angular's HTTP instead of Cordova HTTP. Advantage: Does not require any plugin.
package.json:
"dependencies": {
...
"#angular/http": "4.1.3",
...
}
app.module.ts:
import { Http, HttpModule } from '#angular/http';
...
#NgModule({
declarations: [
MyApp,
],
imports: [
...
HttpModule,
...
]...
calling .ts-class:
import { Http } from '#angular/http';
...
constructor(... , public http: Http, ...) {
//Example: .get for a JSON and map it:
this.http.get(url).map(res => res.json()).subscribe(data => {
this.data = data;
});
}
Answer to first Comment:
As you seem to need SSL Pinning and I did not find an easy way in Angular HTTP yet, i saw that your command of adding the cordova plugin differs a little from the one from the documentation:
You wrote:
ionic cordova plugin add cordova-plugin-http
Now the command seems to be:
ionic cordova plugin add cordova-plugin-advanced-http
(https://ionicframework.com/docs/native/http/)
As you can see there, it supports your needs with methods like enableSSLPinning(enable).
If you are running the app from your pc, you might get such error.
Try using ionicdev
Ionic native plugins depend on the device features. So because of this plugins like http, contacts or camera would not work on your browser. An Example of such error is
Native: tried calling HTTP.post, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator
So try to get ionic's app for developing app here https://play.google.com/store/apps/details?id=io.ionic.devapp
I had the same problem. And I managed to get rid of that error simply by declaring the Angular's HTTP module.
In app/app.modules.ts
import { HttpClientModule } from '#angular/common/http';
#NgModule({
imports: [
// import HttpClientModule after BrowserModule.
HttpClientModule,
],
})
Even if I don't use Angular's Module, this solved my problem.
Have you ever try to call plugin after the platform ready then check platform?
async checkVersion() {
const ready = !!await this.platform.ready();
if (ready && this.platform.is('cordova')) {
// try to add your code here
}
}
you have to remove code from ngoninit and add it in ionviewdidenter
ionViewDidEnter(){
//your code here
}
Related
When i installed latest twilio's version which is "twilio": "^4.7.2", and building the project (npm run build) the following error occurs,
node_modules/twilio/lib/base/BaseTwilio.d.ts:22:19 - error TS2304: Cannot find name 'Headers'.
22 headers?: Headers;
~~~~~~~
Found 1 error in node_modules/twilio/lib/base/BaseTwilio.d.ts:22
My node version : v16.18.1
Npm version : v8.19.2
I got the same issue once I installed the twilio npm package of the exact same version ^4.7.2. I'm assuming it's some typescript compilation issue. And there is a trick that you can use to make it work.
Add this in your tsconfig.json:
{
"compilerOptions": {
"skipLibCheck": true,
}
}
This will solve your issue, but don't consider it as a fix. It's rather workaround.
P.S. This will also speed up your overall typescript compilation process.
I need use code-push service in react-native on iOS platform. Version is 1.17.3-beta.
Local already deployed code-push service. then run the command line to import code-push plug-in.
As shown below.
npm install --save react-native-code-push
react-native link react-native-code-push
Loading code-push module in js.
import codePush from 'react-native-code-push'
There is a problem. prompt codePush is undefined. And I can not call apis for example checkForUpdate() sync().
componentDidMount(){
AppState.addEventListener("change", (newState) => {
newState === "active" && codePush.sync();
});
},
The documents of code-push can be found in node_modules directory,but why not be identified ?
Can any one help please ? Thanks.
Are you sure codePush is undefined?
Try this:
...
const codePushOptions = { checkFrequency: codePush.CheckFrequency.ON_APP_RESUME };
App = codePush(codePushOptions)(App);
AppRegistry.registerComponent('MyApp', () => App);
I have the following code in my TS file...
require("jquery-ui/ui/widgets/datepicker.js");
require("angular-ui-date/dist/date.js");
When I run the code I get the following error...
Module not found: Error: Cannot resolve module 'jquery-ui/datepicker' in //code/my-app/node_modules/angular-ui-date/dist
# ./~/angular-ui-date/dist/date.js 3:66-97
So I ran tsd install jqueryui --save and then added the following to the same file as the require...
/// <reference path="../../../typings/jqueryui/jqueryui.d.ts" />
based on src/main/typescripts but I still get the same warning when running webpack
It seems to be a issue with latest version you are using. It has nothing to do with type definition. if you open angular-ui-date/dist/date.js you will find that it is requiring
require("jquery-ui/datepicker")
which does not exist
to workaround you could change it manually to require("jquery-ui/ui/widgets/datepicker") but that's a ugly solution i think.
There is also an issue on github and there is also suggestion for workaround
Please see the isse here
I added an alias to the resolve object in the webpack configuration file.
'resolve' : {
'alias' : {
'jquery-ui/datepicker' : 'jquery-ui/ui/widgets/datepicker'
},
},
I'm downloading lots of files in the loop and want to setMetadata for each downloaded file (to not backup in iCloud). I'm using simple code with two console.logs. The problem is that files are downloading but no console.log message is displayed. Neither error or success, nothing. Please help.
Code:
var onSetMetadataWin = function() {
console.log("success setting metadata")
}
var onSetMetadataFail = function() {
console.log("error setting metadata")
}
fileTransfer.download(
uri,
filePath,
function(entry) {
entry.setMetadata(onSetMetadataWin, onSetMetadataFail, {"com.apple.MobileBackup": 1});
},
function(error) {},
false
);
This is a bug in cordova-file plugin that has now been fixed in the v1.1.1dev.
If you are busting to try it out you could remove your file-transfer and file plugin and install the development (just remember to add release one back in when it's out).
cordova plugin rm org.apache.cordova.file-transfer
cordova plugin rm org.apache.cordova.file
cordova plugin add https://github.com/apache/cordova-plugin-file.git
cordova plugin add org.apache.cordova.file-transfer
See https://issues.apache.org/jira/browse/CB-6525
I'm boldly stepping into the world of AngularDart, admittedly not knowing too much Dart itself yet. I'm creating a new application that does nothing (yet), except includes the latest 'angular' package.
I'm using Dart 1.2.0 and AngularDart 0.9.9.
Very simple pubspec:
name: myapp
dependencies:
angular: any
My app layout:
pubspec.yaml
pubspec.lock
\lib
\packages
\web
In web I have a simple myapp.dart:
import 'package:angular/angular.dart';
main() {
}
My build seems to work fine, but I get the following warning:
Dart: Build
[Warning from Dart2JS on myapp|web/myapp.dart]:
packages\angular\angular.dart:31:23: Hint: Can't find 'animate' in the library 'angular'.
Is 'animate' spelled right?
#MirrorsUsed(targets: const [
^^^^^^^^
My question is, what does this mean, and is this anything to be concerned about?
This was a bug in AngularDart 0.9.9 and is fixed in current versions.