简体   繁体   中英

Cordova console does not catch exceptions running Ionic on iOS (xcode)

I am writing after spending almost 2 days on this.

For some reason the the console shown on the xcode is different of the console running the App with 'ionic run android -l -c'.

Most of the time we use Android to develop and it does not matter, but when it comes to native features (using cordova), we need to catch the exceptions and errors on iOS environment, and in this case Ionic fails to show me the error and we get totally blind. Productivity goes to zero.

The environment:

MacBook-Air:mobile rodrigo$ ionic info

Your system information:

Cordova CLI: 7.0.1
Gulp version:  CLI version 3.9.1
Gulp local:   Local version 3.9.1
Ionic Framework Version: 1.3.1
Ionic CLI Version: 1.7.16
Ionic App Lib Version: 0.7.3
ios-deploy version: 1.9.1 
ios-sim version: Not installed
OS: Mac OS X El Capitan
Node Version: v6.10.3
Xcode version: Xcode 8.3.2 Build version 8E2002 

MacBook-Air:mobile rodrigo$ cordova -v
7.0.1

MacBook-Air:mobile rodrigo$ npm -v
4.2.0

At packages.json:

  "cordova-plugin-console": "^1.0.7",

Xcode version:

Version 8.3.2 (8E2002)

An example. When something is not defined, I get something like this on Android (ionic run android -l -c):

898806   error    ReferenceError: createByQRCode is not defined
   at new <anonymous> (http://192.168.0.144:8100/js/services/rs-service.js:9:19)

And I get no error on the Xcode console and the app screen gets totally blank .

I've already tried to:

  • remove and reinstall the iOS platform
  • remove and reinstall cordova-plugin-console
  • destroy and rebuild the whole environment

(always doing ionic state reset, etc).

(several times)

For those who might be referring to this question in the future, this helped me a lot: http://docs.ionic.io/tools/developer/#safari-inspector - The Safari's 'web inspector' should be enabled, otherwise you won't see even plain console.log() outputs.

Any help will be appreciated!

As you mentioned, you can turn Develop menu on in desktop Safari
(see https://support.apple.com/kb/PH21491?locale=en_US )

When your Cordova app is running on the emulator or on the real device connected to USB then you'll see devices with JSContexts in this menu. You will be able to see console.log() output and JS exceptions like "someVariable is not defined" .

Can it be that you are creating a production build in xcode and development build with ionic run ? Apps built for production cannot be inspected via Develop menu in Safari.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM