xCode 6 - View console from application running in emulator - ios

I have my iPhone emulator opened not from xCode environment, and I have my application installed on it. In my application I use NSLog to print messages to console.
How can I open a console view for the emulator so I can see the messages printed by the application?

It's simple.
iOS Simluator > Debug Menu > Open System Log.
or Press 'Command + /'
Voila! You would be able to see all your logs now.

Related

How to log in Objective C when iPhone is not attached to Xcode

I am using Xcode Version 13.4.1 (13F100) on a MacBook Pro with macOS Monterey 12.4 and programming in Objective-C.
I would like to log debug messages when my app is running on the iPhone device AND is NOT attached to Xcode. I tried OSLog like described here: https://www.avanderlee.com/debugging/oslog-unified-logging/
However when I open the Console App and select my connected iPhone after running the app the log is empty and I have to explicitly click on "Start streaming" only then I can see my log when I start the app again.
I would like to log when the iPhone is not connected and the app is running and then close the app and connect the iPhone and see the log from the app run. I don't want live streaming but look into past logs.
Is there a way to do that?
I wrote to Apple Developer Support and they said the following:
If you log in your code using OSLog, then you can retrieve those
messages using the Terminal command ‘log’ later on.
For example, with the device named “iPhone" connected to the Mac, you
can retrieve the log info from the last 3 minutes with:
> % sudo log collect --device-name iPhone --last 3m
You can then use Console to look through the saved logs, or you can
parse out the log data from the command line with the ‘log' command.
See its man page for usage.
Here a link on how to use OSLog:
https://www.avanderlee.com/debugging/oslog-unified-logging/
In Objective-C this worked for me:
#import <os/log.h>
os_log(OS_LOG_DEFAULT, "Some message");
I followed Apple Developer Support's advice and it worked for me.

No device logs output after attaching iPhone to process in Xcode

I'm developing iOS apps with Xcode. So when I build through Xcode I get device logs shown in the console output. But when I disconnect the iPhone from USB, or detach the process, then plug in the phone again and try to attach the process (my app is running on the phone still), the console doesn't output anything anymore.
If I go to Window -> Devices and my iPhone it doesn't show any output in that console either. The console app doesn't show any output either. I've tried to kill Xcode, clean the project, but to no success.
Anyone know how to show output logs from the built app after the iPhone have been detached?
I solved the log output mystery. Since we're using Cocoa Lumberjack it "devoured" the normal NSLog output, I added another log output by writing this row:
DEBUG_LOGS([DDLog addLogger:[DDASLLogger sharedInstance] withLevel:DDLogLevelDebug]);
Where DDASLLogger is the apple console.

NSLog not showing in handleWatchKitExtensionRequest, but breakpoints works [duplicate]

I'm just getting started with Apple Watch. I found instructions from "Five Minute Watchkit", on getting the iOS app and the watch kit app both running in the simulator and both processes attached to the LLDB debugger.
What I do is launch and quit the iOS app to install a current version in the sim. Then I switch to the watchKit scheme and launch that, which displays my watch app UI on the watch simulator.
I then launch the corresponding iOS app in the simulator, then user "attach to process" in the Xcode menu to attach the debugger to the running iOS app.
This works. I can set breakpoints in either the watch kit InterfaceController or in my iOS app and the debugger breaks there when it should.
However, I'm not seeing NSLog() statements in the debug console from my iOS app. (I do see log statements from the WatchKit extension code.) If I set a breakpoint in my iOS app, it does stop at that breakpoint when it should. I assume the lack of console output from NSLog has SOMETHING to do with attaching to a running process on the sim rather than launching it from Xcode, but I don't know what that something is.
(BTW, attaching an action to a breakpoint that invokes NSLog from the breakpoint also doesn't display, but the "log message" debugger command DOES display.
Does anybody have any insights?)
EDIT:
The code in the iOS app doesn't seem to matter. In my case, it was a dirt simple IBAction that was attached to a button in the iOS app storyboard:
- (IBAction)buttonAction:(UIButton *)sender;
{
NSLog(#"Button clicked on iPhone");
}
I can set a breakpoint on that NSLog statement. The debugger stops at that line, but I don't see the log statement in the debug console.
I can reproduce that with a simple test app, sans WatchKit. The app consists of a NSTimer that prints "Timer fired" every second. (This code is 100% correct ;). Nothing shows in the log after I have manually attached to the process.
As far as I know NSLog outputs to stderr, I guess attaching the debugger does not redirect stderr to the Xcode terminal.
If you are okay with using the console app or the terminal to look at your logs you can do that. iOS8 stores simulator logs in ~/Library/Logs/CoreSimulator/<Device-UUID>. In this directory you will find a system.log, which contains all your NSLog output.
You can look at it in terminal (cat, grep, tail), or open it in the Console.app.
Apple confirms that (at least for GDB) in Technical Note TN2239: iOS Debugging Magic.
Console Output
Many programs, and indeed many system frameworks, print debugging
messages to stderr. The destination for this output is ultimately
controlled by the program: it can redirect stderr to whatever
destination it chooses. However, in most cases a program does not
redirect stderr, so the output goes to the default destination
inherited by the program from its launch environment. This is
typically one of the following:
If you launch a GUI application as it would be launched by a normal
user, the system redirects any messages printed on stderr to the
system log. You can view these messages using the techniques described
earlier.
If you run a program from within Xcode, you can see its
stderr output in Xcode's debugger Console window (choose the Console
menu item from the Run menu to see this window).
Attaching to a
running program (using Xcode's Attach to Process menu, or the attach
command in GDB) does not automatically connect the program's stderr to
your GDB window. You can do this from within GDB using the trick
described in the "Seeing stdout and stderr After Attaching" section of
Technical Note TN2030, 'GDB for MacsBug Veterans'.
The mentioned TN2030 is no longer available on their server (mirror). It showed how you can redirect stdout and stderr to the Xcode console. However, since shell tty isn't a valid command for LLDB it won't help much. But maybe there is a different way to access the tty Xcodes console uses, so I attach the important part of that TN.
Seeing stdout and stderr After Attaching
If you attach GDB to a process (as opposed to starting the process
from within GDB), you won't be able to see anything that the process
prints to stdout or stderr. Programs launched by the Finder typically
have stdout and stderr connected to "/dev/console", so the information
they print goes to the console. You can view this by launching the
Console application (in the Utilities folder), however, it's
inconvenient to have to look in a separate window. Another alternative
is to connect the process's stdout or stderr to the terminal device
for GDB's Terminal window. Listing 9 shows how to do this.
Listing 9. Connecting stdout and stderr to GDB's terminal device.
(gdb) attach 795
[... output omitted ...]
(gdb) call (void) DebugPrintMenuList()
No output )-:
Close the stdout and stderr file descriptors.
(gdb) call (void) close(1)
(gdb) call (void) close(2)
Determine the name of the terminal device for GDB itself.
(gdb) shell tty
/dev/ttyp1
Reopen stdout and stderr, but connected to GDB's terminal.
The function results should be 1 and 2; if not, something
is horribly wrong.
(gdb) call (int) open("/dev/ttyp1", 2, 0)
$1 = 1
(gdb) call (int) open("/dev/ttyp1", 2, 0)
$2 = 2
Try the DebugPrintMenuList again.
(gdb) call (void) DebugPrintMenuList()
Yay output!
Index MenuRef ID Title
----- ---------- ---- -----
<regular menus>
00001 0x767725D3 -21629 Ed
00002 0x76772627 1128 <Apple>
00003 0x767726CF 1129 File
00004 0x76772567 1130 Edit
[... remaining output omitted ...]
To add onto Filipp Keks answer, here's a visual representation of a much much simpler way to do it than the accepted answer.
From Filipp Keks's answer:
Plug in the device and open Xcode
Choose Window -> Devices from the menu bar
Under the DEVICES section in the left column, choose the device
To see the device console, click the up-triangle at the bottom left of the right hand panel
Click the down arrow on the bottom right to save the console as a file"
This screenshot was taken in Xcode 7.3.1 of the Devices window.
With Xcode Version 7.2 and iOS 9.2 etc, I found the following works:
Kill both the phone app and watch apps
Select the Watch Extension Target and hit Cmd+R (build and run)
Select the Phone target and hit Ctrl+Cmd+R (Run without building)
In my case, I have both apps up in their simulators and get NSLog output for both. I don't need to attach separately. Hope this helps.
https://developer.apple.com/library/ios/qa/qa1747/_index.html
Plug in the device and open Xcode
Choose Window -> Devices from the menu bar
Under the DEVICES section in the left column, choose the device
To see the device console, click the up-triangle at the bottom left of the right hand panel
Click the down arrow on the bottom right to save the console as a file
When your Provisioning profile is set to AdHoc or Distribution then Xcode doesnot show log, you need set development to view log
This might not solve showing up NSLog messages, but it might be helpful when debugging app started in background.
You can use the breakpoint feature that allows you to log messages.
The idea is to:
Create a breakpoint with "Automatically continue after evaluating actions" checked
add "Log message" action (you can also use expressions and print out values, for example: "Log message #variable#")
Attach debugger using anticipated process name (XCode will wait for the process to start)
Trigger app start.
Credits and details:
https://fluffy.es/how-to-debug-app-which-got-launched-push-notification/
In my case a set Automatically to see NSLog, before don't show at all
I came to this question, via this one (Xcode console empty after attaching to process) which is now closed.
My issue is that the debug console in Xcode is showing nothing (just an empty white box).
The solution for me is a tiny toggle at the bottom which changes between "variable view" and the actual debug console.

Error in using UIAutomatorviewer for testing Android app in Appium

I have to automate an Android application, I am doing the same through Appium.
The problem I am facing is after launching the Appium server, the app is getting installed in the emulator 4.4.2. To inspect the element I am using UIAutomatorviewer which comes default with SDK. But while inspecting the element of the app, I am getting the error:
Error obtaining UI hierarchy
Reason:Error while obtaining UI hierarchy XML file.com.android.ddmlb.SynchException.Remote object doesn't exist.
I tried to find the solution so that I can inspect the element so that I can script, but in vain.
Can someone please tell how to fix the issue so that I can inspect elements?
Is there any other way I can inspect element in the app apart from using UIAutomator viewer?
After my tryst with the uiautomator viewer i came to know that we get the error only when:
appium server is running and we try to capture the screenshot using uiautomatorviewer.
So, whenever you want to use uiautomatorviewer make sure that server is in stopped state.
I fixed the same issue by using following methods.
(1) Connect your Android device to your development machines;
(2) Go to command line in terminal or DOS command line for Windows;
(3) Using "adb shell" into your Android devices;
(4) Change the user to root by input "su root" in command line;
(5) Change the access right to /data/local/tmp by input "chmod 777 /data/local/tmp";
(6) Go back to uiautomatorviewer and do screen shot again, the error should be gone;
I guess there are some file can't be access if it doesn't own right in /data/local/tmp.
Make sure everything on your screen is static. And flashing input cursor is also not allowed. Any painting actions will stop uiautomator from dumping current UI.
You can test by using following adb command:
adb shell uiautomator dump /data/local/tmp/uidump.xml
if the message ERROR: could not get idle state. appears, you are suffering from this issue.
See lines 87 & 101 of DumpCommand:
try {
...
uiAutomation.waitForIdle(1000, 1000 * 10);
...
} catch (TimeoutException re) {
System.err.println("ERROR: could not get idle state.");
return;
}
Easiest solution..
Restart the device. Restart uiautomatorviewer.
Worked like a charm for me .... :P
Stop the Appium Server. Then try again. It works.
I had the same problem because I used "adbd insecure". So I just disabled "adbd insecure", and reload uiautomatorviewer, everything is OK.
In case of rooted devices: Enable the root access in developer options for adb. Restart adb as root
I have spent over a week to resolve this issue. When you connect your device and using ASM 3.0, when screen is projected open the UIAutomator to capture the current android screen. Without Appium it should capture. For use Android Studio instead of android sdk. Uninstall and reinstall Android Studio. It is working perfect for me now.
Answer to your question #2
You can inspect Android app directly from your real Android device.
You need to:
Connect Android device to your computer/laptop
Go to Android device Settings -> Enable Developer Options and Android debbuging
Please see here:
Start the app you wish to inspect in your Android device
Open up the Chrome browser on your computer/laptop and do a right click -> More Tools -> Inspect devices -> Click on your device -> (Click on Android device OK to authorize) -> Click Inspect
Please see here:
That's it. Hope it helps!
I got also the same issue (Also if Appium Server was not running). After switch, OFF / ON USB-Debugging was working for me.
I got it resolved
I closed the Appium Server running on my machine and opened it again.
Later open uiautomater, and it worked for me
The one that works is in this path:
Android/Sdk/tools/bin/uiautomatorviewer
Paste this in your terminal and it will run automator that works
we have to use device which has API level morethan 17 or jelly bean
Way to bypass the ERROR:
could not get idle state.
By using uiautomator to get uix and screenshot.
public class DeviceMethods extends UiAutomatorTestCase {
public void dump(){
try {
getUiDevice().dumpWindowHierarchy("window_dump.uix") ;
getUiDevice().takeScreenshot(new File("/data/local/tmp/window_dump.png"));
} catch (Exception e) {
}
}
you need to create the uiautomator jar and push it to /data/local/tmp
use this tutorial on how to use uiautomator
after you get the files just open them in uiautomatorviewer
What worked for me:
stop appium
open an emulator device (tested with Android 7.1.1)
go into settings > developer options > Enable view attribute inspection
open a shell on the computer, cmd or terminal depending on your OS
enter the following commands:
adb shell
su
cd /data
cd /local
chmod 777 tmp
start uiautomatorviewer
take an xml screenshot
"su chmod 777 /data/local/tmp" didnt work for me so I drilled down and it worked. I assume that you have to do this in an emulator and not a physical device unless the device is rooted. ¯ \ _ (ツ)_/¯
Lotsa Luck!
This happens because adb is using port and it's blocked by appium server.
I have found out best solution for this
Kill the adb.exe from taskbar processes and try launching uiautomatorviewer again
Check whether you have enabled these under "developer options" in the phone.
Verify apps via USB
View attribute inspection
USB debugging
1) stop appium Server
2) open an emulator device
3) go into settings > developer options > Enable view attribute inspection
4) developer options in invisible? Go into settings > Tap on About device/phone > Scroll down till the last option(Build number) > Continuously Tap on "Build number" for 7 times > you should get an Toast message "You're a developer" > come back from that screen > Go back into settings > Now you should see developer options Tap on it > Enable view attribute inspection
5) You should no more get this error message
Why don't you use appium inspector instead? You can download it and follow instructions from here
try switching Off and then ON the USB debugging option.. this work for me

Unable to launch application by using start_test_server_in_background

I have tried to open my application using start_test_server_in_background. I can see the iPhone simulator but my application is not opening in the simulator. It's showing the following error message.
Note: I have set APP_BUNDLE_PATH.
Any suggestions?

Resources