Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 690
ohho Avatar asked Jun 04 '14 07:06

ohho


People also ask

How do I debug a widget extension?

To debug your widget, select the widget-extension target in Xcode and choose Product > Run.

How do I debug iOS app on real phone?

Plug your iPhone into your computer. You can select your device from the top of the list. Unlock your device and (⌘R) run the application. You'll see Xcode install the app and then attach the debugger.

What is debug mode in iOS?

Debug mode enables you to see logs of various Tapjoy actions (sessions, placements, purchases, custom events, etc. ). These will appear in the Tapjoy Developer Console. This setting also enables logging to the Xcode console.


3 Answers

  1. Debugging works for app extensions.
  2. It works on simulator too.
  3. 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.
  4. Steps to debug an app extension:

    1. Run the container app. In this step, Xcode uploads the container app and app extension to the device or simulator.

    2. 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.

    3. 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.)

    4. 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:

  1. Run your extension in the simulator.
  2. 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.

like image 124
Vince Yuan Avatar answered Oct 23 '22 16:10

Vince Yuan


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).

enter image description here

like image 24
BalestraPatrick Avatar answered Oct 23 '22 15:10

BalestraPatrick


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:

enter image description here

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.

enter image description here

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.
like image 32
Andrew Avatar answered Oct 23 '22 17:10

Andrew