console.log is not working in iOS Phonegap App even after adding the console plugin
Solution 1
I have solved this issue by doing these steps
Step 1 :
I Just copy a directory from another cordova project where console.log was working
sudo cp -r DIFF_CORDOVA_PROJECT_PATH/platforms/ios/www/plugins/org.apache.cordova.console CURRENT_CORDOVA_PROJECT_PATH/platforms/ios/www/plugins/
Step 2 :
Add the Code in CURRENT_CORDOVA_PROJECT_PATH/platforms/ios/www/cordova_plugins.js file under module.exports JSON array
{
"file": "plugins/org.apache.cordova.console/www/console-via-logger.js",
"id": "org.apache.cordova.console.console",
"clobbers": [
"console"
]
},
{
"file": "plugins/org.apache.cordova.console/www/logger.js",
"id": "org.apache.cordova.console.logger",
"clobbers": [
"cordova.logger"
]
}
Step 3 :
Adding Meta data on the same cordova_plugins.js file in module.exports.metadata JSON Array :-
"org.apache.cordova.console": "0.2.7"
Solution 2
In my case the reason was probably because the plugin was installed from a Windows machine the first time and it work previously only for the Android platform. when I try to reinstall it from my Macintosh I encountered the same problem of Shashi.
This has been caused from the missing of the source file CDVLogger.m in the compile source list. So I recommend to check if this file is already added by:
Click on root Project file in the Xcode explorer > Build Phases > Compile Sources section
If the CDVLogger.m file is not present add it and try to Run the project again. This fixed the issue for me.
EDIT: In addition be sure that your index.html page contains this HTML:
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
Solution 3
I tried a lot of solutions posted here in stackoverflow but nothing was working for me. After putting the cordova.js outside of my personal JS folder console.log was working fine.
<script charset="utf-8" src="cordova.js"></script>
Shashi
9 Years Experience | FullStack | Javascript | NodeJS | ExpressJS | NestJS | GraphQL | Angular | MySQL | MongoDB | Docker | Kubernetes | Microservice | Kafka | RabbitMQ | Redis | Newrelic | DevOps | AWS | GIT | Phonegap | Ionic Frontend: Bootstrap, Javascript, Typescript, Angular, React, Backbone, MarionetteJS, Ionic Framework, Apache Cordova Backend: NodeJS, ExpressJS, GraphQL, NestJS, Mongoose and Sequelize ORM, EJS, Handlebar, PHP, Redis, RabbitMQ, Apache Kafka. Unit Testing & Code Quality: Mocha & Chai (Unit Test), SinonJS, SonarQube. Database: MongoDB (Replication & Shrading), MySQL, Postgres, DynamoDB & Parse.com Cloud DevOps: Tools Git, Docker, Kubernetes, Jenkins, CI/CD Pipeline, Terraform, JFrog, Elastic Search, Kibana, NewRelic, Grafana, Nginx, Apache Cloud Services AWS Cloud: IAM, Cognito, Lambda, EC2, ELB, S3, VPC, Route53, API Gateway, SNS, SQS GCP : Compute Engine, Cloud DNS & Storage, GKS, Speech-to-text, Dialogflow, API Gateway, CloudBuild, Firestore, Cloud Functions Others : Azure IoT, Mongo Atlas, SSL Integration, DNS Management Domain: Microservices, Web Apps, STB / OTT / SmartTV Apps, Hybrid Mobile App, eCommerce. Profile - [LinkedIn Profile] - [Facebook Profile] - [PhoneGap Developer Directory] - [Code Project Profile] [LinkedIn Profile]:http://in.linkedin.com/pub/shashi-badhuk/30/b46/145 [Facebook Profile]:https://www.facebook.com/aarush.badhuk [PhoneGap Developer Directory]:http://people.phonegap.com/developer/shashi-badhuk [Code Project Profile]:http://www.codeproject.com/Members/Shashi-Badhuk
Updated on June 16, 2022Comments
-
Shashi almost 2 years
I have created a Phonegap iOS App in Cordova CLI . I have added the console plugin and yes deviceready is called successfully but console.log is not working and does not print any thing in XCode log.
Plugin Installation :-
cordova -v
3.3.1-0.3.1sudo cordova plugins add org.apache.cordova.console
Fetching plugin "org.apache.cordova.console" via plugin registry
Starting installation of "org.apache.cordova.console" for ios
Preparing ios project
org.apache.cordova.console installed on ios.sudo cordova plugins ls
[ 'org.apache.cordova.console',
'org.apache.cordova.device',
'org.apache.cordova.dialogs',
'org.apache.cordova.geolocation',
'org.apache.cordova.globalization',
'org.apache.cordova.inappbrowser',
'org.apache.cordova.media',
'org.apache.cordova.network-information',
'org.apache.cordova.splashscreen',
'org.apache.cordova.vibration' ]Java Script :-
var app = { initialize: function() { this.bindEvents(); }, bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); }, onDeviceReady: function() { app.receivedEvent('deviceready'); }, receivedEvent: function(id) { console.log('Device Ready Received'); //It is not working alert("Device ready called"); //It is Working } };