Debug Ios App On Mac

broken image


Debugging Apps That Have Been Submitted or Deployed To reproduce bugs that appear in the submitted build of your app, use the Archive feature in Xcode to test the exact build of your app that was submitted to the App Store or Mac App Store. Find out more about this and other processes to resolve issues reported by users or App Review. Safari can be used to debug an Ionic app on a connected iOS device or iOS simulator. First, on the iOS device, enable Web Inspector from Settings Safari Advanced. Next, open Safari on a Mac then enable Show Develop menu in menu bar under Safari Preferences Advanced.

There are some features of iOS apps that don't work from the iOS simulator. Maybe you want to test how your application works with the device camera or send an SMS message from your application. For these examples and more you'll need to test and debug your app using a real device.

This post will walk through how to run the Xcode simulator on your iPhone or other iOS device and show you how to fix some common errors you'll see along the way.

How to select your iPhone as the 'Simulator' Device

Simulator is in quotes here since this will create an actual app on your phone; it's no longer a simulation. Open up a project in Xcode and click on the device near the Run ▶ button at the top left of your Xcode screen.

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. The application should pop up on your phone.

Troubleshooting Common Errors

The first time I tried to connect my iPhone to Xcode it didn't work. According to my best friend, Stack Overflow, I'm not the only one who has had issues. Let's share the fixes to some common errors you might encounter.

'Signing Requires a Development Team'


Xcode requires that you've connected a Team to your project in order to run the simulator on a device. You can do this from the 'General' tab of your Project Settings. As of Xcode 7 this can be any Apple ID.

Open the Team menu that currently says 'None' and select your team. If you don't have a team, select 'Add an Account…' and create one with your Apple ID.

Ios

Xcode claims your device is locked when it isn't

How

Xcode claims your device is locked when it isn't

This fun bug has been happening since at least Xcode 6. There are a lot of potential solutions in this Stack Overflow post. Here's what worked for me:

  1. Unplug your iPhone
  2. Reset Location & Privacy on your iPhone. Found under Settings >> General >> Reset
  3. Plug in your iPhone
  4. Hit Trust when prompted to Trust This Computer

You can learn more about how trusting computers works from Apple's support.

'iPhone is Busy'

The unsatisfying answer for this one is to just wait.

If you don't have a sword fighting partner, you can try the following:

  1. Unplug your device
  2. Restart both Xcode and your iPhone
  3. Plug in your device

That worked for me, but a lot of folks had luck with 'Solution #3' from this Stack Overflow post.

Activate your Debugging Superpowers

The Jasonette docs FAQ has some more tips if you have other related issues. Now that you've got your application running on a device you can make the most of your testing and debugging experience with these tips:

If you have any questions or run into any other issues, feel free to reach out to me on Twitter @kelleyrobinson.

-->

Xamarin.iOS applications can be debugged with the built-in debugger in Visual Studio for Mac or Visual Studio.

Use Visual Studio for Mac's native debugging support for debugging C# and other managedlanguages code and use LLDB when you need to debug C, C++ or Objective C codethat you might be linking with your Xamarin.iOS project.

Note

When you compile applications in Debug mode, Xamarin.iOS will generateslower and much larger applications as every line of code must beinstrumented. Before releasing, make sure that you do a Release build.

The Xamarin.iOS debugger is integrated into your IDE and it allowsdevelopers to debug Xamarin.iOS applications built with any of the managedlanguages supported by Xamarin.iOS in the simulator and on the device.

The Xamarin.iOS debugger uses the Mono Soft Debugger, which means that the generated codeand the Mono runtime cooperate with the IDE to provide a debuggingexperience. This is different than hard debuggers like LLDB or MDB which controla program without the knowledge or cooperation from the debugged program.

Setting Breakpoints

When you are ready to start debugging your application the first step is to set breakpoints your application. This is done by clicking in the margin area of the editor, next to the line number of code you want to break at:

You can view all the breakpoints that have been set in your code by going to the Breakpoints pad:

If the Breakpoints pad does not display automatically, you can make it visible by selecting View > Debug Windows > Breakpoints

If the Breakpoints pad does not display automatically, you can make it visible by selecting Debug > Windows > Breakpoints

Before you begin debugging any application, always ensure that the configuration is set to Debug, as this contains a helpful set of tools to support debugging such as breakpoints, using data visualizers, and viewing the call stack:

Start Debugging

To start debugging, select the target device or similar in your IDE:

Then deploy your application by pressing the Play button.

When you hit a breakpoint, the code will be highlighted yellow:

Debugging tools, such as inspecting the values of objects, can be used at this point to get more information about what is happening in your code:

Conditional Breakpoints

You can also set rules dictating the circumstances under which a breakpoint should occur, this is know as adding a conditional breakpoint.

To set a conditional breakpoint, access the Breakpoint Properties window, which can be done in two ways:

  • To add a new conditional breakpoint, right-click on the editor margin, to the left of the line number for the code you wish to set a breakpoint on, and select New Breakpoint:

  • To add a condition to an existing breakpoint, right-click on the breakpoint and select Breakpoint Properties or in the Breakpoints Pad select the properties button illustrated below:

You can then enter the condition under which you want to breakpoint to occur:

To set a conditional breakpoint in Visual Studio, first set a regular breakpoint. Right-click on the breakpoint to display its context menu:

Select Conditions... to display the Breakpoint Settings menu:

Here, you can enter the conditions under which you want the breakpoint to occur

For more information on using breakpoint conditions in earlier versions of Visual Studio, refer to Visual Studio's documentation on this topic.

Navigating through code

When a breakpoint has been reached, the Debug tools enable you to get control over the program's execution. The IDE will display four buttons, allowing you to run and step through the code.

In Visual Studio for Mac they will look like the following:

These are:

  • Play/Stop – This will begin/stop executing the code, until the next breakpoint.
  • Step Over – This will execute the next line of code. If the next line is a function call, step over will execute the function, and will stop at the next line of code after the function.
  • Step Into – This will also execute the next line of code. If the next line is a function call, Step Into will stop at the first line of the function, allowing you to continue line-by-line debugging of the function. If the next line is not a function, it will behave the same as Step Over.
  • Step Out – This will return to the line where the current function was called.

In Visual Studio they will look like the following:

These are:

  • Play/Stop – This will begin/stop executing the code, until the next breakpoint.
  • Step Over (F11) – This will execute the next line of code. If the next line is a function call, step over will execute the function, and will stop at the next line of code after the function.
  • Step Into (F10) – This will also execute the next line of code. If the next line is a function call, Step Into will stop at the first line of the function, allowing you to continue line-by-line debugging of the function. If the next line is not a function, it will behave the same as Step Over.
  • Step Out (Shift + F11) – This will return to the line where the current function was called.

For more in depth documentation on Debugging, see the Navigate Code with the Visual Studio Debugger.

Breakpoints

How To Debug IOS App In Physical Device Without Mac Machine ...

It is important to point out that the iOS givesapplications only a handful of seconds (10) to startup and complete theFinishedLaunching method in the Application delegate. If the application doesnot complete this method in 10 seconds, then iOS will kill the process.

This means that it is almost impossible to set breakpoints on the startupcode of your program. If you want to debug your startup code, you should delaysome of its initialization and put that into a timer-invoked method, or in someother form of callback method that is executed after FinishedLaunching hasterminated.

Device Diagnostics

If there is an error setting up the debugger, you can enable detaileddiagnostics by adding '-v -v -v' to the additional mtouch arguments in your Project Options. This willprint detailed error information to the device console.

Wireless Debugging

The default in Xamarin.iOS is to debug your application on your devices overthe USB connection. Sometimes the USB device might be needed to testplugging/unplugging of the cable for developing ExternalAccessory-poweredapplications. In those cases, you can use debugging over the wirelessnetwork.

For more information on Wireless Deployment and Debugging, refer to the Wireless Deployment guide.

Technical Details

Xamarin.iOS uses the new Mono soft debugger. Unlike the standard Mono debuggerwhich is a program that controls a separate process by using operating systeminterfaces to control a separate process, the soft debugger works by having theMono runtime expose the debugging functionality through a wire protocol.

On startup, an application that is to be debugged contacts the debugger andthe debugger starts to operate. In Xamarin.iOS for Visual Studio, the Xamarin Mac Agentacts as the middle-man between the application (in Visual Studio) and the debugger.

This soft debugger requires a cooperative debugging scheme when running onthe device. This means that your binary builds when debugging will be larger asthe code is instrumented to contain extra code at every sequence point tosupport debugging.

Accessing the Console

Crash logs and the output of the Console class will be sent to the iPhoneconsole. You can access this console with Xcode using the 'Organizer' andselecting your device from the organizer.

Alternatively, if you do not want to start up Xcode, you can use the Apple's iPhone Configuration Utility to directly access the console. Thishas the added bonus that you can access the console logs from a Windows machine if you are debugging a problem in the field.

For Visual Studio users, there are a few logs available in the Output window, but youshould switch over to your Mac for more thorough and detailed logs.

Debugging Mono's Class Libraries

Debug Ios App On Mac Shortcut

Xamarin.iOS ships with the source code for Mono's class libraries, and you canuse this to single step from the debugger to see how things are working underthe hood.

Since this feature consumes more memory during debugging, this is turned offby default.

To enable this feature, make sure the Debug project code only; do not step into framework code option is deselected under the Visual Studio for Mac > Preferences > Debugger menu as illustrated below:

To debug the class libraries in Visual Studio, you must disable Just My Code under the Debug > Options menu. In the Debugging > General node, clear the Enable Just My Code checkbox:

Visual Studio - How To Debug A Xamarin.iOS App On A Physical ...

Once you do this, you can start your application and single step into any ofMono's core class libraries.

Debug Ios App On Macbook Pro

Related Links





broken image