Application is not working after stoping it from `xcode.` - ios

Here is the simple example , Application have a button ,on clicking it should print Check. It is printing when I am running from Xcode (*very simple).But after clicking on stop button on Xcode and then launching the app again from icon this time , the button is not printing anything.
Code:
- (IBAction)save:(id)sender
{
NSLog(#"check");
}
What is the reason behind this?

When you stop Xcode running an application it stops receiving messages from the app. And when you running it again from Simulator Xcode knows nothing about new process.

Adding to #njuri, you can connect to the process from Xcode that was started outside of Xcode.
Click the Debug menu and choose Attach to Process then "By Process Identifier (PID) or Name" and enter your app's name. You can hit breakpoints and inspect the process. It does not recapture the stdout though. To see your logs, go to the Devices tool (Shift-Command-2)

When you run from xcode, the output is redirected to the debug console. This does not happen by default when you run from the icon.
However, you can ask to see the output by selecting Debug -> Open System Log... from the top bar menu.
So open the system log and then run your app from the icon and you will see the output.

Related

Xcode 9, where are my NSLog()s going? Not showing in Xcode console or Console.app

I'm trying to do some basic logging while I work on an app. I tossed some NSLog()s into my code, but nothing is being printed to the Xcode console below. Literally nothing, not even some startup info as the app launches, etc.
I've got my Xcode console set to display All Output and I've got the variable inspector and the Console open:
I heard about Logging changes and that a new Console.app was introduced that would let me view the logs on the simulators as well, so I thought maybe the logs would show up over there, but while I do so lots of system messages happening I don't see the NSLog()s that I'm making.
Am I missing something? Is there a new setting I need to flip? Where can I see my NSLog()s?
EDIT:
I was doing this with an iOS 11 simulator and got no console output. When I switched to an iOS 9 simulator then I got all of the console output.
Figured it out. It's not an intermittent issue or one that can just be fixed with a restart. It's a Run configuration issue.
Click on the Run Scheme selector in the top left of Xcode's toolar.
Click Manage Schemes.
Click on your main App Project.
Click the Edit button in the bottom left.
Uncheck OS_ACTIVITY_MODE.
Click Close.
Viola. All your console logs come back.

Testing a closed ios app

I'm currently trying to handle different application states (closed, background or in a different tab of the app) however when I try to test how the app works when it is closed and receives a push notification(double click home and force close the app then reopen it) I'm not sure where I'm going wrong in the code. Since I'm reopening the app from the phone itself and not xcode I can't test to see which method isn't being reached because no output is available in the console. Is there any way to test a situation like this or simulate a force close event in xcode so that when i re run the app on the phone it also launches in xcode?
I appreciate any responses.
Cheers!
If you force close app or stop (from xcode) then it close the connection with xcode. Then if you open it from phone then it will not make connection with xcode. You must run it from xcode. And there is no difference in opening app from phone or running from xcode. App's flow will be same in both case. So what you want to test that which methods get calls and in which sequence that you can check by rerunning the project.
Update:
Select the Scheme on the toolbar (just left beside from your device or simulator list)
Choose Edit Scheme
Select Run in the left panel
For the Launch option, select Wait for executable to be launched
Refer this link for more details
Since I'm reopening the app from the phone itself and not xcode I can't test to see which method isn't being reached because no output is available in the console.
In Xcode, hold down the Option key and choose Product->Run..., and then edit the Run scheme to use the "Wait for executable to be launched" option. You should then be able to choose Run in Xcode, and then open your app by some other means, such as responding to a notification, and Xcode will still connect and let you debug.
To debug the process after restarting the app again, attach the Xcode debug console to the running process.
In Xcode do:
Debug > Attach to process > [select your process]

How can I debug an iOS app executed in mobile not launched by Xcode?

I am developing an application for iOS in Objective C with Xcode. This application schedules local push notifications every 6 hours and it is crashing when I open the push notifications.
I need to debug the error to solve it. I can have the mobile connected to Xcode, but as the app is executed from local push notification I can't see the error messages on my Xcode debug console, as I haven't launched my app from Xcode.
Is there a way to have the iOS device connected to my Mac and see what error is happening?
I know that I can go to the mobile settings to view logs, but these logs are too ambigous for me aren't giving any error.
In addition to opening the console log as described by #saurabhgoyal you can tell Xcode to wait for your app to launch and then attach the debugger to it when it does.
Select the scheme you're using to build your app, select edit scheme, and click on the run icon. Then Look for a pair of radio buttons titled "Launch" and select the one with the name "Wait for executable to be launched."
Then when you run your app in Xcode it builds it and installs it on the device but does not launch it.
When your notification fires and the app launches the debugger attaches to your app and you can debug as normal (except that NSLog statements don't print to the debug console any more - an annoyance.)
Yes there is a way to see device logs on Mac.
Connect your iOS device to the Mac system using USB
Launch Xcode–>Window–>Devices
Select your device from the left panel
Now you can see the logs on the screen including the background activities.
In order to save the running logs.
Reproduce the issue or start working on your device on a the app you wanted to capture the logs. After the issue is reproduced click on the Save Console icon bottom right corner Xcode screen
For more details please visit this link
Hope this Helps!
Check your crash log
1.Launch Xcode on your desktop machine.
2.Open the Xcode Devices window. (Window menu -> Devices and Simulators, or Cmd-Shift-2.)
3.Find your device in the left sidebar, then select “device logs”.
Choose a Chrome crash (or multiple crashes) and select “Export” at the bottom of the Organizer window.

Xcode not showing logs after exiting the app and come back

I'm using Xcode 6.1 and running an app on the Simulator. When the app exits by double-tap home button, no logs show any more from Xcode console when I come back to the app. Anyone knows what's going on. Appreciate
You need to launch (run) the app from Xcode into the simulator in order to get Xcode's debugger to attach and stream the simulator's console output into the debugger window.
You can also view the Simulator console output by looking at a system log file, details for which can be found in this related question.

How to attach debugger to iOS app after launch?

I have an issue I am troubleshooting which occurs very infrequently and doesn't seem to happen when I have things running under Xcode.
Is it possible to run an app normally (i.e. from Springboard) until my issue occurs, and then attach a debugger at that point?
I would prefer to do this without jailbreaking if possible.
Attach your device connected your Mac
Debug > Attach to Process by PID or Name
In the dialog sheet, enter the name of your App as it appears in the Debug navigator when started via Xcode (e.g. Target's name not bundle-id).
If the app is already running, the debugger will attach to the running process. If it isn't running, it will wait for the app to launch and then attach.
I'll leave this here since neither of the other 2 answers gave me quite enough detail without a little bit of a struggle.
Run your app in the simulator and take note of the name in the Debug navigator
Plug in your device and don't forget to select your device as the target
Debug > Attach to Process > By Process Identifier (PID) or Name
Enter the name from step 1 and attach. That should be all you have to do.
In Xcode 5.0.1 and 6 it's the menu bar items:
Debug > Attach to Process > By Process Identifier (PID) or Name...
In Xcode 7 it's just:
Debug > Attach to Process by PID or Name...
I was able to debug the app by adding a breakpoint on the AppCoordinator file init() method on the super.init() line.
I was able to turn off the wifi/internet and then by pass the developer verification.

Resources