How to debug iOS 8 extensions with NSLog?
- 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.
iOS 8: How to properly setup extension to debug it in Xcode using simulator?
In addition to this answer https://stackoverflow.com/a/24043265/1136433 which says how to view logs of the extension app, in that log you can also check the PID of the extension.
Let's say you have the following NSLog statement:
NSLog(@"Testing");
Execute the extension and in the system.log you will see something like this:
Sep 11 11:13:40 my_machine.local today[5689]: Testing
Where 'today' is the name of the extension you are executing (in my case was a Today Extension) and the '5689' is the extension PID.
So, now you can go to Xcode -> Debug -> Attach to Process and then you can set breakpoints and debug the code.
Hope this can help somebody
KeyboardViewController NSLog IOS 8
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.
Answered here:
for physical device: https://stackoverflow.com/a/24050325/1453948
for simulator: https://stackoverflow.com/a/24043265/1453948
So in case of simulator go to Simulator menu Debug -> Open System Log
iOS 8 beta 5 Today view extension (widget) stuck at Waiting to Attach
Do not stop & start the debugger while notification windows is open in the simulator. Close the notification window. Stop the debugger. Start it again. Debugging widget in iOS8 is very delicate. You need to do everything in a slow non-agressive way (for now).
Print to console from application extension
Your most reliable choice is to use NSLog
for debugging purposes, but println
might actually be working in this case. You just need to attach the Xcode debugger to the extension itself.
In my experience, it's a rather buggy process. This answer has more info on the subject. In short, you need to change the target in the Run drop down to your extension, then after you click run you should get a list of things you can run it in.
Related Topics
Making Text Bold Using Attributed String in Swift
Uinavigationbar Custom Back Button Without Title
How to Debug iOS 8 Extensions With Nslog
How to Build For Armv6 and Armv7 Architectures With iOS 5
Uitapgesturerecognizer - Single Tap and Double Tap
How to Make App Fully Working Correctly for Autorotation in iOS 6
How to Add a Touch Event to a Uiview
Modal Dialog Does Not Dismiss Keyboard
Add Views in Uistackview Programmatically
Uicollectionview Inside a Uitableviewcell - Dynamic Height
Uinavigationbar Hide Back Button Text
Uilabel - Auto-Size Label to Fit Text
Reading Nfc Tags with iPhone 6/iOS 8
How to Increase the Height of Navigation Bar in Xcode
Nsphotolibraryusagedescription Key Must Be Present in Info.Plist to Use Camera Roll