See logs before & after app restart - ios

I have my iPhone app running on device, I can see logs in xcode.
Then, I what to see logs about what is happening when app restart.
So, I press home button twice -> swipe up to stop my app, then launch the app again. But I can't see any log in xcode anymore.
How can I see logs of my app continuously before & after my app restart in xcode?
==== UPDATE ===
I mean app log. OK, I can narrow my question to: How can I see logs again after I restarted my app? (device is connected to my mac book , I saw app logs in xcode before restarting, but can't find a way to see app logs after I restarted my app).

You can't see logs of an app that is not running. I can tell you this if you're really curious : there is nothing to log anyway. :)
Now you might want one of those things :
System logs :
Just go in the Device Manager of XCode (short cut is Shift-Apple-2 I think). It's in the Window Tab, under Devices. Select the device you're running on, then you'll have the logs available there.
This logs everything the device logs, so there will be a LOT of text.
App logs :
Those are the ones you already have, but you seem to clearly want the "restart" logs of your app. There is no such thing as a restart log. What you have is the logs at the start of your app, and the ones at the end. For example, what you logged in your AppDelegate's didBecomeActive or willTerminate (or even didEnterBackground).
You will only see the logs of the didBecomeActive when you actually run the app from XCode (otherwise the debugger is offline). He will start the app as if you tapped on the app icon, so no worries there.
If you decide to kill the app by swiping up, it will log the app delegate, and you'll just be able to browse it in the debugger. You can put a breakpoint if you want to make sure it enters the AppDelegate methods.
But if you want to restart the app again, you'll have to re-run it from Xcode, not manually start it on the phone.
File logging :
Another very easy solution is to log everything on a text file in the Documents directory of your app, you'll then be able to start/quit as much as you want, and let it log on the file. You can later read that file like any other file :)

In case you want to just show the device logs you may want to take a look at this answer:
https://stackoverflow.com/a/19148654/691977

Related

How to debug a crash which happened when come back from background

There is a crash happen when coming back from background through app icon.
However I cannot see any detail info in console log. There is a signal to terminate, but we cannot find signal number.
<FBApplicationProcess: 0x117bcb930; Maixxxx; pid: 1762> exited abnormally via signal.
Process exited: <FBApplicationProcess: 0x117bcb930; Maixxx; pid: -1> -> <FBApplicationProcessExitContext: 0x17103f820; exitReason: signal; terminationReason: (none)>
The procedures to reproduce my crash is as follow:
Start app through click on app icon.
Use the app as normal user.
Press home to put it in background.
Wait for some minutes.
Click the app icon on springboard screen in order to use it again.
The app crash&exit.
Since the crash only happen when coming back from background, and required to enter background for some minutes, I cannot run in debug mode with lldb attached.
I didn't use any of background features.
Also, I didn't see any crash report in Fabric's Crashlytics. So I think signal handler could not be called neither?
How to investigate this kind of problem?
These things can be tough, I know that from similar experiences. Without knowing more about your app I can only offer hints and no definitive answer, but perhaps this helps you.
The fallback and tedious approach to use direct logging with print and so on notwithstanding there are a two ways to try to "catch" a process.
However, first let me stress that "background" is not always the same and people unfortunately use the term often loosely. Depending on what state transition causes your crash you might run out of luck and have to simply experiment using manual logging. Apps can be in background, i.e. not in the foreground, but still running. This is usually the case when the debugger is attached, otherwise it couldn't do its job. Alternatively they can be suspended (or even terminated) by the OS. The debugger prevents this, which you probably already figured out.
The two things that might help you are:
If you're using background fetch, i.e. "coming back from background mode" as you describe it happens automatically you can activate the "Launch due to a background fetch event" option in your build scheme's "Run" configuration section.
Run your app from the Home screen, put it into background with the Home button and wait a bit (you've probably done so in the past already to get a feeling for when the crash would happen). Your app should eventually go into the suspended state (but you have no way to actually see that anywhere AFAIK). Instead of getting it to the foreground again via the multitasking UI, simply attach the debugger again via the "Debug - Attach to process" menu. This should get your app from the suspended state back into the background state, where the crash probably really happens (if it were to happen when coming from background to foreground you probably would have been able to debug it as usual). Hopefully the debugger has finished attaching to it in time, otherwise I'm out of ideas. :(
I haven't run into this specific problem myself personally, but I know background stuff can be tricky. Maybe this discussion also helps you (I took part of my info from there as well).
Run the app in debug mode on a real device. Press the Home button to send the app to background and continue the debugging. Then you can bring the app to foreground and keep debugging, or put a breakpoint at applicationWillEnterForeground.
You can't debug this on the real device. When the debugger is attached, your apps will never go to background mode in the real device.
You can try to debug this on a simulator.
Anyway please check your class attributes and set attributes to strong to make sure this is not happened by missing attributes.
I have read several StackOverflow questions that have FBApplicationProcess. Usually, this one happened by missing array or something when the app started.
Best regards.
I have gone through all the above answers and all have given proper answers. Though, I would like to share my point of view.
If the app is running on any iOS real device with debug mode and wire plug-in or even on Simulator, App will never go in the background.
If the app is running without wire plug-in or run without Xcode(directly launch the app in iPhone) and then put the app in the background, the app will be running in the background of next 3 mins. After 3 mins, the App will automatically be suspended and removed from the main thread. Now, when we open the app again, It will be considered a fresh launch.
If your app having any Background Capabilities ON, then your app will be alive even in the background, but you can't do any UI changes during that time.
To keep app alive in the background, Background Capabilities must be handled properly. ie. If Location is used in your app with 'While-App is in Foreground' condition, app will not run more than 3 mins in background. So, If you want to run your app continuously in background, you must have to represent proper reason in Info.plist file with Battery drain word, or else, Apple will reject it.
Ping me for more detail on your question.
Thanks.
Crash logs still available on your test device.
To get the crash log try the following steps:
Connect your test device to the Mac through USB.
Launch Xcode. Go to Windows > Devices and Simulators.
Choose your device from the devices section on the left side of the screen.
Select View Device Logs button.
Identify and select the Crash Log to see the contents.

Is there way to get the stack trace of an iOS device that running your app?

I have an iOS app that I side-loaded to 5 of my testers onto their phones.
1 of them reported that the app is crashing, but I can’t seem to reproduce it.
He also can’t seem to reproduce it either.
Is there way to get the stack trace of an iOS device that running your app?
Is there away that he can sent his logs to me via email or some kind of cloud service like Firebase?
Should I look into any technology?
If you get the person to bring their phone to you, you can plug it in to XCode and read the logs that way, however, you won't be able to go back and view logs from days past. But, if they plug in and run the app and are able to recreate the crash, then you'll have it right there.
It is possible to write code in your app to write log data to a file that you save on your phone. To keep from filling up your phone storage, I delete that file when the app is closed and create it new when the app is started. Then, I created a method in the app to contact support, and I attach the log file to the e-mail. This works great as long as they click the contact support button before closing out of the app. However, if the app crashes, then you could code it to keep the log file if it already exists on the next startup.
Keep in mind that once you start sending the log data to a file, it will no longer show up in your console when you are debugging your app, unless you code some sort of easy switch to flip to turn that feature on or off.

Swift application quits after open, works from Xcode

I am encountering a strange situation with a simple application I develop. When I deploy the application using Xcode (with debugger attached), it works perfectly.
When I close Xcode, disconnect the phone, kill and restart the application, it works just fine, too! For several hours that is.
After some time (usually the next day morning) when I try to open the app up, it immediately fails. A white rectangle filling the screen animation does happen, but when the application is supposed to flash its UI in, it quits instead.
How can I get ahold of the crash logs from the iPhone? Does it store any? This application is not from the AppStore, it's my development application installed through Xcode.
When I re-deploy it after finding this has happened again, hoping I'll get something with a debugger attached, it starts working again. This has happened to two of my apps.
You could try to look into your device's logs: Window->Devices -> Select your device-> Click 'View Device Logs'. Find your app crash there and on the right side you should see a crash report.

iOS: Simulating user quitting app

I just added persistent data into my app and wanted to test it with my iPhone. When I quit my app (double tap home and swipe up), I'm unable to open it again (the icon freezes). When I try the same thing on the iOS simulator in Xcode, it crashes too. I get a SIGTERM error coming from my AppDelegate. Is this what is supposed to happen when the user quits while testing, or is this an issue with my data? Is there any way to simulate the user quitting and restarting the app to make sure my data is still there?
Thanks
This is not what is supposed to happen when the user quits while the Xcode debugger is attached (at least not anymore — this question is a couple years old after all).
If you force quit an app while running from Xcode (whether simulator or on a physical device) it just stops the debugger and you should be able to relaunch it without issue. The Xcode debugger will not be attached when you launch like that, but from Xcode you can attach the debugger to an existing process (Debug > Attach to Process).
Note, if run in Xcode and then you quit the simulator application on your Mac (or close the simulator's window) then you will get a SIGTERM error in main.swift. But this is not the same as a user terminating your app, nor is it comparable to a user turning off their device.
From what you're describing it sounds like there is a bug in your code that is causing it to freeze when launching when the debugger is detached or when it's relaunching after termination.
To simulate the user quitting and restarting you should be able to terminate the app from your device/simulator, and then either run it again from Xcode or launch it from the device/simulator and attach to the process from Xcode.
In some cases it may be helpful to put in some debugging code that pops up an alert / update some label at runtime to indicate the data persisted properly after the app re-launched so that you don't always have to have Xcode attached to diagnose problems in your app.
This is the correct behavior if you are running the app from Xcode. However, once you've uploaded/run the app once, you can test closing and reopening it. Simply stop the run in Xcode, go to your phone or simulator, and click on the app icon to open it. Unfortunately, you won't have a debugger log at that point, but you can see if your data persists.

How to detect when user exits ios application on jailbroken device

For an unknown reason, when I kill my app in the recent menu and try to launch it again, the last screen where I was appear again and the device is frozen. What I have to do is a hard reboot and after that, launching the app again work...
Alternatively, if I want to relaunch my app after the kill in recent without a reboot, I have to type this command in mobile Terminal
killall myapp
and after this, if I try to launch my app from homescreen, my app is working correctly...
What I wanted to know is how could I detect when the user exit the app with the home button and thereby launch an NSTask that send killall command ? I know NSTask is not allowed by Apple but this is a jailbreak app that is not intended to be published on Apple Store.
Also this bug really bored me... in viewDidLoad I've several NSTask and method that check if directory exist. Do you think that these things can disallow the app from being relaunched after a kill in recent and freeze the device ? Or this is because the app run as root and there is somethings to do especially from allow the device to relaunch the app in this situation ?
Thanks in advance for your help !
First off, I want to point out that using NSTask isn't always the answer. You can use NSFileManager. to manage files and directories, and you can use exit(0) to terminate your process.
As far as your actual question, is your application running as root? When applications are told to close by iOS, they are sent a SIGSTOP signal by SpringBoard. Since SpringBoard runs as mobile, these signals are sent by the mobile user, meaning that root applications will not receive them. This means that whenever a root application is told to quit, it just ignores the request and keeps executing. To fix this, there is a key in the Info.plist you can change.
Go ahead and set UIApplicationExitsOnSuspend to the boolean true in your Info.plist and see if that fixes your problem.
Ok for the first question I've found how to: I've placed a NSTask method into didEnterBackground (AppDelegate class) that kill the app when the user exit the application
For the second question I really don't know... I've deleted the method placed into viewDidLoad to see if that was the cause of the issue but nothing, as soon as I kill the app in the recent and try to relaunch it, the device froze.. Because there is nothing in viewDidLoad method, I think the issue is caused by the root right... The NStask in DidEnterBackroung solve this issue

Resources