Nothing in Xcode Debugger after Archiving for release - ios

I recently archived and uploaded my app for release for the first time. However, now when I try to print to the debugger, nothing is appearing. Also, breakpoints are not being activated when I run the simulator.
I am using Xcode 7.3, the latest at the time of this writing. My app contains a keyboard extension. Neither are printing to the debugger or triggering breakpoints. The debugger pane is set to show "All Output".
As far as I can tell, it is still using the "Debug" scheme, I never manually changed it. Would it have changed when I archived and uploaded the .ipa to iTunes Connect? What would have changed?
With your suggestion, can you be thorough in your suggestion? I may not have enough experience with Xcode to understand immediately, so the more explanation the better.

Look at the "Run Scheme" for your Project (Product->Scheme->Edit Scheme or option-click on the Run button) and check the Build Configuration pulldown. Make sure that's Debug, not Release.
BTW, you can also tell what binary is actually getting run by running in the debugger, hit the Pause button, then in the Debugger Console, type:
(lldb) image list <AppName>
That will show the path to the binary that got loaded. If this is the Release version that should show up in the path and you'll know you are debugging the wrong configuration...

In archiving my app, Xcode combined the scheme of the Containing App and the Keyboard extension. As a result, the Containing App was the only selection possible when choosing a scheme and the output of the Keyboard Extension was no longer sent to the debugger.
In order to solve this, I selected "Product > Scheme > New Scheme..." and then selected my Keyboard Extension to be its own Scheme again. Once the Keyboard Extension was a scheme again, it was able to be selected as the target scheme to send output to the Debugger.

Related

Today Extension Breakpoints not triggered in Xcode 8.3.2

I try to debug my Today Extension. When I run the scheme for the Today Extension on my Device I can see all NSLogs. But all Breakpoints get ignored so far. The host app can be debugged normally.
That means I already attached my Today Extension target to the debugger.
I already tried to delete the DerivedData folder.
I already tried to reset my Xcode Defaults.
break list returns all breakpoints which are set.
Any ideas?
when I was developing today extension, I was debugging it like this:
1) I ran my app on device
2) Debug > Attach to process by PID or Name > type my_process_name ( see screenshot )
3) Click attach, then it worked
I was able to identify the problem:
It is necessary to add each source file to the Today Extension Target. Otherwise it is not possible for the Debugger to find the breakpoint in my case.
But this is more complicated to change. Because of our current architecture. But now I do know that Xcode works as appropriate.

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]

Can I debug iOS app installed from IPA archive?

I m having some problem with my app which reproduces only when i install it ad hoc, but doesn't reproduce if i just run the app from Xcode. I would like to debug this problem, but so far i m not having any luck. I m using Xcode 5.1.1. Here is what i did:
1) Go to Product->Scheme->Edit Scheme->Archive and set build
configuration to Debug.
2) Code signing identity is set to iPhone Developer.
3) Generate Debug Symbols is set to Yes.
4) Go to Product->Archive and after it is archived, click
"Distribute", then choose "Save for Enterprise or Ad Hoc Deployment".
5) My development provisioning profile is selected.
6) Click "Export" and export the .ipa file.
7) Use iPhone configuration Utility to install the app onto the
device.
8) Run the app on the device.
9) In Xcode, go to Debug->Attach To Process->By PID or Name, enter the
app name. Xcode attaches successfully and says running the app on
iPad.
10) However, i cannot hit any breakpoints which should be hit when i
do certain actions in my app (if i install and run the app from Xcode
instead, all breakpoints are hit).
Am i missing something?
You don't have any debug information for the app at this point, and since most apps are pretty thoroughly stripped, there won't even be symbols for lldb to hook on to. So we're not going to be able to successfully set breakpoints.
When you built the app, Xcode produced a dSYM file (MyApp.app.dSYM) which has the debug info in it, so all is not lost. Problem is when you attach to some - to Xcode - random app on the device, Xcode has no way to know where to find its debug info.
You can add the debug info into your debug session in lldb by using the command:
(lldb) add-dsym <PathTo.dSYM>
You have to do this after you have attached.
lldb also uses SpotLight to find dSYM's so if you put the dSYM somewhere that SpotLight knows to search (like your Desktop or a folder under your User directory) then lldb should pick it up automatically.
You can tell whether lldb has successfully read in the dSYM by doing:
(lldb) image list <AppName>
If lldb found the dSYM, it will list the path to it on a separate line after listing the path to the AppName binary.
Jim Ingham, thanks for your answers.
I found the reason why i was unable to debug into static libraries. In each Xcode project, there is a setting called "Strip Linked Product" under "Deployment" section. In all my projects this setting was set to "Yes".
In order to debug into static libraries for an app built by archiving, i set this setting to "No" in each dependent library project (as well as the main project). This can also be set differently for Debug/Release modes. After this, i see the library symbols built during archiving and i m able to debug into library code. I hope this helps someone.
Unfortunately (or maybe fortunately) the bug i was trying to debug no longer reproduces when the library symbols are not stripped. Maybe something happens when the symbols are stripped, i will need to investigate further.
I was struggling with the same problem, and just launching my app from Xcode was not an option - I had to build the IPA, sideload it on an iOS device, and then debug. Eventually I was able to make that work with the following steps:
1) Set the scheme archive target to Debug
2) Change the following settings for the Debug builds
Keep Private External Symbols (KEEP_PRIVATE_EXTERNS) : YES
Enable Bitcode (ENABLE_BITCODE) : NO
Strip Linked Product (STRIP_INSTALLED_PRODUCT) : NO
3) Rebuild, archive, and deploy the resulting IPA file to your iOS device.
4) Launch the app, and in Xcode, select Debug/Attach to Process/YourAppName(id)
5) Break into the debugger - you should be able to see the code, put and use breakpoints, etc.
If you want to debug your code from the very beginning, just put a loop that sleeps for a second or two and then checks a flag at the top of your main function - when you break into the debugger, just change the flag to let it escape the loop.

Can't debug iOS 8 App Extension

I'm trying to debug the sample Action App Extension provided on Xcode 6 (6A313).
Even though the app runs flawlessly, I can't see any NSLog messages on the Debug Area neither Xcode will stop on my break points.
Things I've tried:
I've tried uninstalling Xcode 6, re-downloading it from the Mac Store and installing again with no success.
I've also tried to go through Debug -> Attach to Process -> By Process Identifier (PID) or Name... but the Status Bar shows "Waiting for -bundle id- to launch" when it is already running.
Tried different devices.
Tried running on the simulator, but my App Extension won't show on the App Extensions list (it is not present in the "more" list also).
I've checked this answer also, which didn't help me.
I've ran out of ideas on what to do :)
When you added the Application Extension target Xcode should have added also a new Scheme for the Extension (or you can create one in 'Manage Schemes...').
If this happened you just have to change the Active Scheme, on the very left of the drop down with which you choose the device/os of the simulator, and run.
If you change the Active Scheme to the Widget one, then breakpoint and NSLog works, at least for me.

How to debug iOS 8 extensions with NSLog?

- (void)viewDidLoad
{
NSLog(#"%s", __func__);
// ...
}
in viewDidLoad of an iOS 8 extension. the NSLog outputs nothing in Xcode. NSLog works as usual in the container app though.
How can I get output from debug messages from an extension?
Debugging works for app extensions.
It works on simulator too.
If your app ext crashes in the simulator, you may find it is not easy to restart your app ext. Restarting your simulator is a quick solution.
Steps to debug an app extension:
Run the container app. In this step, Xcode uploads the container app and app extension to the device or simulator.
Stop the container app. This step is important when you debug in simulator. If you don't do it, Xcode will tell you the simulator is in use.
In Xcode, press menu Debug -> Attach to Process -> By Process Identifer (PID) or Name..., input the app ext's identifier, e.g. com.abc.ContainerApp.MyExtension, to start debugging. Don't forget to set break points. (Update on Aug 25, 2014: you can input MyExtension(your extension's name) directly.)
In the device or simulator, open your app extension.
Updates on Aug 23, 2014:
I found the debugging steps above do not work well on Xcode 6 beta 6 with iOS 8 SDK beta 5 on the simulator.
Solution:
Run your extension in the simulator.
Xcode menu Debug -> Attach to Process -> Choose "MyExtension(your extension's name)" in System section in the menu.
The breakpoints work. But I don't know why logs do not show in the output window.
I'm having this problem too. It works for me if you go in your Simulator under the menu Debug -> Open System Log...
From here you can see all the logs of the iPhone Simulator (included your extension's logs).
NSLog is working perfectly.
You just don't see what is being logged in the debug area of Xcode because the Xcode debugger isn't attached to your extension. Extensions are nearly completely independent from their containing app. They have separate bundle identifiers, for example, and they also are separate processes on the OS.
I have had varied success in getting Xcode to attach to extensions. Supposedly it seems it would attach automatically, and it appears in the debug navigator as "Waiting to attach", but never attaches.
Sometimes, I am able to run my extension target in Xcode:
And then have the option to choose what application to run my extension in. In this case, I would choose its recommendation of "today", which is notification center.
And then it would sometimes attach the debugger to my extension. Note this method only works on physical devices, it seems.
If it doesn't attach you can use the manual attachment method in #VinceYaun's answer,
I have also had varied success using other methods of attachment. Most have been unsuccessful, and it seems they are just bugs that will be fixed at a later date.
To view your log messages you go to Window -> Devices in the top bar and select your device. You can bring up the device log from the bottom of that window. If you are testing on a simulator, you can use #BalestraPatrick's answer.
Some of the bugs have been fixed in Beta 2, and my guess is that eventually the debugger will attach automagically when launching the extension.
Update: In the iOS 8 Beta 4 release notes:
Extensions
Fixed in beta 4
Extensions sometimes fail to launch when debugging from Xcode.
When Extension with UI is killed, it relaunches and is not dismissed.
Sometimes your Sharing or Action extension can hang.
Redeploying an extension may disable it in Notification Center.
I'm having this problem too. Xcode never attaches my debugger to the extension or displays NSLog messages. If you attach your Xcode debugger manually to your extension process, at least breakpoints work like a charm:
Debug->Attach to process->Your extension name (mine was "com.example.MyExtensionApp.MyExtension")
Create scheme for your extension
Run scheme
In a dialog choose container app
Enjoy
It works for me :)
Xcode 8 is able to debug extensions:
Choose the extension scheme in the combo next to the stop button and run it.
Select the parent application in the dialog that appears.
Result: breakpoints and log work as usual.
What finally allowed me to see the log in the debugging area, based on Michael's suggestion and Apple's documentation, is:
Build & Run the app extension in the simulator and, when prompted for a host app, choose the specific app that you're going to call the extension from. In my case I was launching my Action extension from Safari by pulling up a share sheet on a PDF.
What wasn't working before was following other people's suggestions of using Today as the host but then leaving that app and going over to Safari to call my extension. I no longer even need to run my containing app first before running the extension.
From Apple's Documentation:
In your extension scheme’s Run phase, you specify a host app as the executable. Upon accessing the extension through that specified host’s UI, the Xcode debugger attaches to the extension.
I actually got the logs to run quite simply in Xcode 6.3. Firstly, build and run the containing app. Once the containing app is running on the device, build and run the app extension by changing the scheme to the app extension.
Apple has documentation directly related to debugging, profiling and testing your app extension.
A trick which works for me (although it is quite an ugly one) is to place a dummy UILabel somewhere in the bottom corner of my extension. I usually call it logLabel. It is then possible to update the text of this label with any log statement that you want to get logged. Such approach is not very good if you need to log statements from instances of different classes. And, obviously, it clutters your UI.
However, if you have a fairly simple widget and you don't mind about slight cluttering of the UI this does the trick. I have tried all other solutions outlined in this discussion and, sadly, none of them worked for me.
The only way debugging works for me is by selecting Debug->Attach To Process By PID or Name
Then enter the PID not the extension name.
You can find the PID by running the extension on a device, go to Window->Devices. Find your device and viewing the console. When you see the name of your extension, its followed by 5 digit number. That is the PID
I also put a bunch of NSLog's in the extension in order to find the PID as well.
This is on xCode 7
Encounter the same problem about extension for NSLog, and break points. I have fought it with many days.
Device log can be found as following image. It is at XCode -> Window -> Devices and Simulators.
After enter the Open Console, there is a search field at the top-right of dialog. I can apply filter rule in there. For example, a process name contains Notification key word, or process name must equal to the name of extension target, ex: equal to MyNotificationServiceExtension process name.
Clearly something is broken in Xcode6-B5.
If I try to run a Photo extension on the Simulator I cannot see any Photos.app as an option for the extension attaching process.
The same, running on a real device, give me the correct behaviour.
In the first case any breakpoint is not honorated. In the latter case, breakpoints work like a charm.
You should know that the container app and extension are totally two difference process in iOS while the LLVM debugs only a thread a time, so when you are debugging, the console never log the extension and never stop at breakpoint.
You can solve most of the problems by #Vince Yuan's method.
However, my problem is that Xcode debugger hardly hook on my keyboard extension on both iOS Simulator and devices, like 1 time in 7-8 runs, It's totally a matter of probability. #Vince Yuan's method also work for just sometimes.
My little experience is that when you run you debug scheme, if the debug Session in the left panel showing that 'No Debug Session', there is no need to open your extension and test it, the debugger didn't hook on, just run again for lucky.
but when you see com.xxx.xxx.xxx is waiting to Attach, the extension can definitely get debugged.
This is a little trick for whom cannot debug iOS extension, especially keyboard extension.
As of Xcode 6 Beta 5, I've been able to use an actual device running iOS8 to debug my extension. Try running it on a device and select Safari to launch into
To overcome all the states caused by ever changing IDE, I'm using iOS Console by lemonjar.com – it displays a console window for any connected iOS device rendering syslog messages regardless the process ID. You can see both app and extension debug log messages at once here.
I could debug my extension with the way I describe below:
Xcode : Debug -> Attach to process by PID or Name. Your extension scheme name.
Then select your main app target and run.
I hope it also works for you guys.

Resources