Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying iOS Development with Xamarin Cookbook
  • Table Of Contents Toc
iOS Development with Xamarin Cookbook

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
4 (13)
close
close
iOS Development with Xamarin Cookbook

iOS Development with Xamarin Cookbook

4 (13)
By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
close
close
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1
Index

Debugging our application


This recipe provides information on debugging a Xamarin.iOS app on the simulator.

Getting ready

Xamarin.iOS, in combination with Xamarin Studio, provides a debugger for debugging apps either on the simulator or on the device. In this recipe, we'll see how to use the debugger for debugging Xamarin.iOS apps. Open Xamarin Studio and load the ButtonInput project. Make sure to set the project configuration to Debug | iPhone.

How to do it...

Perform the following steps to debug your application:

  1. Xamarin Studio supports breakpoints. To activate a breakpoint on a line, click on the space on the left of the line number to set it. Set a breakpoint on the following line in the ButtonInputViewController.cs file:

    this.labelStatus.Text = "Button tapped!";

    The following screenshot shows what a breakpoint in Xamarin Studio looks like:

  2. Compile and debug the project by clicking on the Run button or by navigating to Run | Start Debugging on the menu bar. Xamarin Studio's status will display the message Waiting for debugger to connect….

  3. When the simulator is opened and the app is loaded, watch the information that is provided in the Application Output pad.

  4. Tap on the app button. Execution will pause and Xamarin Studio will highlight the breakpoint in yellow. Move the mouse over the labelStatus variable in the breakpoint line. A window will be displayed with all the evaluated variable's members, as shown in the following screenshot:

  5. To stop debugging, click on the Stop button in the toolbar.

How it works...

The debugger that is used is called soft debugger. It is called so because it depends on both the runtime and Xamarin Studio, combined to provide one unified debugging platform. When the debugging process starts, Xamarin Studio begins listening for debugging information from the app. The same applies for debugging on both the simulator and the device. When the app executes, it starts sending information back to Xamarin Studio. It then displays that information in the Application Output pad, which is automatically activated. A typical application output when debugging is the information on the assemblies that are loaded, the threads that begin execution, and the breakpoints, if any, that are available.

There's more...

The Console.WriteLine() method can also be used for debugging purposes. The debugger takes care of this and redirects the output of the method to Xamarin Studio's Application Output pad.

App performance when debugging

When compiling for debugging purposes, the compiler produces larger and slower code. This is because it generates extra code that is needed to provide the appropriate debugging information. That's why, when debugging an app, the execution of the app is much slower than on simple running situations. Before producing a release copy of the app, remember to compile it with the Release | iPhone project configuration to avoid slow runtime execution.

Breakpoints in FinishedLaunching

One more reason for not to have complicated code in the FinishedLaunching method is that, in most cases, you will not be able to debug it. If you set a breakpoint in FinishedLaunching, app execution will pause, but iOS will terminate the app when the time limit is reached.

See also

  • The Creating profiles recipe in Chapter 14, Deploying

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
iOS Development with Xamarin Cookbook
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon