Tag Archives: xCode

NativeScript and Console logging on iOS (including XCode 9)

Been a while since I posted; and most this info was going to be presented at the NativeScript Developer days speech that we ran out of time in our cool session.     So I'm going to present it here, because I think this will help a lot of people.

First of all, NativeScript has an issue (at least on my machine) where the logging is incomplete and missing important things, like crash reports (and now on XCode 9, non-existent).

Well, when I ran into the two first issues using XCode 8.2 & 8.3.   I figured out a work around, because I hate my tools not working.    🙂

There is a really awesome set of utilities called libimobiledevice this set of utilities lets you do all sorts of things with a real iphone when it is connected to your computer including reading the logs.

 

Real Devices (any version of iOS)

So I typically do idevicesyslog | grep CONSOLE and it will then show me all my logs for the device and it basically fixes any issues other than some exception reporting.   Most the time my app doesn't crash so that command above I use probably 99% of the time.    However in the cases I need to see the NativeScript actual crash logs.   I use the above command and it will spit out the PID of your app next to the CONSOLE word.  I then cancel it, and do a idevicesyslog | grep <PIDID> and this gives me the full log including anything the NativeScript runtimes print.

Please note this only works for real devices.

Simulators (iOS 10 and before)

UPDATE for iOS 11 simulators, please see below!

Now for simulators; the process is very similar.

You run xcrun simctl list | grep Booted and it will give you a line like this:
iPhone X (4701B6F6-0EE4-423F-B5E2-DE1B5A8C32AC) (Booted)

Do you see that big old long uuid; you need that.

tail -f ~/Library/Logs/CoreSimulator/4701B6F6-0EE4-423F-B5E2-DE1B5A8C32AC/system.log | grep CONSOLE

This allows you to grep the log from that specific simulator.   Again, using the grep CONSOLE filter you can limit it to any console logs.   And you can also use grep <PIDID> to filter it to any application if you need the filtered down to, if you are needing the specific NativeScript application level logging or crash reports too.

 

Simulators (iOS 11)

iOS 11, changed the logging for the Simulator drastically.  Technically iOS 10 changes the NSLog drastically, but 11 enforced some new rules.   So iOS 11 broke the NativeScript internal logging; but it broke the cool tail trick above.    Everything now is now running through the new os_log facility.  The easiest way to get logging from your simulator is this single line:

log stream --level debug --predicate 'senderImagePath contains "NativeScript"'
--style syslog

Please note this is case sensitive, if you don't case the senderImagePath and NativeScript you won't have your filtered logging (or any logging at all if you type it wrong).   This part of it filters it down to just any NativeScript logging from all emulators running.

I created a simple bash script called /usr/bin/local/tnslog and dropped the above line it in and then chmod +x /usr/local/bin/tnslog 'd it.  So I can easily just start tns, and then open another terminal tab; and type tnslog and have all my logging again.

 

Installation

The simulator you need no extra tools.   For real devices you need the libimobiledevice toolset, which you can easily install via brew with the following two commands:

brew install --HEAD usbmuxd

and

brew install --HEAD libimobiledevice

It is really important that you install from head, the changes in Xcode 9 and iOS 11 have made a couple changes to both those libraries require some updates and the normal brew packages are out of date and doesn't have it.  So you need the latest and greatest.

 

Final Thoughts

I have been lazy, and just documented the steps.   If someone has some spare time and wants to create a quick bash script to automate the grabbing of the simulator id, and starting the older logging; against that simulator that would be cool to add to our tools.  But since I'm using primarily iOS 11 emulators now; my tnslog script handles all logging until the NativeScript team can fix their tool's issues.

 

NativeScript: iOS xCode 7.2+ Code signing fix!

For the last couple months since xCode 7.2 was released, those poor iOS developers who upgraded to 7.2 have felt much pain if they installed any Cocoapods. If you didn't use any PODs you were fine.  But the minute you used a plugin that has a POD; you were in for a world of hurt.  And this error: CodeSign error: entitlements are required for product type 'Application' in SDK 'Simulator - iOS 9.2'. Your Xcode installation may be damaged.  Was our only clue to what was wrong, not very helpful since Simulator apps aren't supposed to be signed.

The solutions that I handed out was to either to de-install and downgrade to 7.1 or to  build the app inside of the xCode environment.  Neither were great solutions.

I saw the solution appear a couple days ago in the issues; and finally had time to upgrade my environment back up to 7.2.1 to test and verify before I spread the good news.

I can't take credit for the fix, that goes to Ivan & Dimitar at Telerik who figured out why those using xCode 7.2+ could no longer use the TNS command line to build our applications.   The fixes will be showing up in the new v1.6 which should be released any day now; but in the meantime I figured I would document the fix so that you can apply it to your projects now.  And unless you are planning on uninstalling the iOS runtimes and install them again in v1.6; you will still have to manually apply this fix to any existing projects.

xcode-Fix-1So lets say your app is named: MyAwesomeApp.   You need to navigate to your MyAwesomeApp/ platforms / ios / MyAwesomeApp / folder and then edit the build.xcconfig file. In the picture above the app is called crossCommunicator; so you will see that the path for the file for my app is crossCommunicator / platforms / ios / crossCommunicator / build.xcconfig.

Open that file up and then you should see something like this:

xcode-Fix-2You see that line that says:
CODE_SIGN_IDENTITY = iPhone Developer?
Comment it out, so that it now says:
// CODE_SIGN_IDENTITY = iPhone Developer

xcode-Fix-3

Save the file, and you are all set to go!   You can now use xCode 7.2+ and Cocoapods fine!