How to debug iOS app


 

Last Updated: 26 Feb 2015

Scope

  1. Types of errors: Compile Time Errors
  2. Types of errors: Runtime Errors
  3. Debugging app yourself: 101
  4. Debugging app yourself: Update Xcode
  5. Debugging app yourself: Installing Project Dependencies
  6. Debugging app yourself: Recreating Project Scheme
  7. Debugging app yourself: Most common errors

Types of errors

There are two types of errors. Compile time and Run time. If you’re not familiar with Objective C then correcting these errors will be very difficult for you. So in that case its always best to send the error logs to us. Next two sections discusses how to send the error logs to us for Compile time and Run time errors.

Types of errors: Compile Time errors

They prevent your application from being run and they can be inspected in Issue Navigator (command + 4). If you app shows a red mark with white exclamation mark inside it then its a compile time error. Fig 1.

How to debug iOS app

Steps to follow in case of compile time error occurs.

  1. Open Issue navigator. (cmd + 4)
  2. There may be two sections. One under red mark and other under yellow marks. (Fig 2 A) The red ones are important. Click each error message under red marks and take screenshot of Xcode. Fig 2 B, 2 C.
  3. Also copy error message in each step and send it with all screenshots taken in step 2. Fig 3

How to debug iOS app

How to debug iOS app

How to debug iOS app

How to debug iOS app

Types of errors: Runtime Errors

Runtime errors occurs while app has built successfully and code is syntactically all right but due to unexpected conditions at runtime app crashes. e.g divide by zero error.

We don’t get any information on such errors via issue navigator but we get some info from console.A typical runtime error looks like Fig 4 which shows console output. Most of the time it shows error in main.m file which is inside Supporting Files group.

How to debug iOS app

Steps to follow in case of runtime errors

  1. Show console by pressing shift + cmd + C.
  2. Copy the error message and send it to us.
  3. Also send us the screenshot.

Debugging app yourself: 101

Most basic thing you can do is

  1. Hit command + shift + K to clean the project and then try re-building or re-running the project.
  2. Sometimes error is due to misconfigured Cocoapods, follow this guide for troubleshooting Cocoapods related error. Cocoapods Advanced Troubleshooting Guide
  3. Also if you have accidentally misconfigured few things or changed some code, start afresh.

Debugging app yourself: Update Xcode

All apps are created from latest Xcode so for smoother setup its recommended to have latest Xcode on your system too. Steps are:

  1. Open App Store on your Mac.
  2. Under updates section check for any pending system updates.
  3. Type this command on Terminal

    code-select —install
    
  4. If it says

    
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

    

    Then your Xcode is updated

  5. Else it will open a dialog which will ask you to install Xcode command line tools similar to image below. Click Install to download and install them. Its heavy and it will take time depending upon your internet connection speed.

How to debug iOS app

Debugging app yourself: Installing Project Dependencies

Many times our project build fails only due to some misconfiguration, missing components/files or old libraries. For this all iOS projects are built over Cocoapods, which is a dependancy manager and takes care of all of the above problems.

Introduction to Cocoapods

So Cocoapods is a dependancy manager (just like rubygems). It is based on Ruby and mac comes with Ruby and so you can just type

sudo gem install cocoapods

to install it. More information on http://cocoapods.org/.

If you already have a version of Cocoapods installed then try updating it by running same command.

Now opening .xcworkspace file combine two projects into one. The iOS App and its dependancies. In the project navigator you can see them as two large blue icons at root level of tree. The latter is always called Pods. Inside it you’ll find a file called Podfile and if you open it you’ll find name and version of all dependancies. A sample file looks like this.

source ‘https://github.com/CocoaPods/Specs.git’
target ‘FBDemoSDK’ do
pod ‘Facebook-iOS-SDK’, ‘~> 3.20’
end
target ‘FBDemoSDKTests’ do
end

It says that App FBDemoSDK app requires Facebook-iOS-SDK to be installed. ‘~> 3.20′ means that it will install versions 3.20 onwards upto 3.29.

pod ‘Facebook-iOS-SDK’, :head

above line will always install the latest bleeding edge version on the SDK which might be risky sometimes but beneficial also. (more info: http://guides.cocoapods.org/using/the-podfile.html)

Installing dependancies

So if you get errors related to some libraries used then this is you’re going to do first.

  1. Open terminal.
  2. Close Xcode.
  3. Navigate to your directory.

    cd /path/to/your/project/folder

  4. Type this command

    pod install

    (Note: As of current version of Cocoapods you’ll need at least Ruby 2.1 for this to work correctly. Please check cocoapods.org for the correct version of Ruby to be used.)

    this command will take some time to update dependancies or install missing dependancies. Be patient until it finishes.

  5. If the above method also fails then try updating the Pods by typing this command

    pod update

Debugging app yourself: Recreating Project Scheme

Go here Xcode Schemes

Debugging app yourself: Most common errors

  1. ld: library not found for -lPods

    – Generally this happens when Xcode is unable to locate your Pods.
    – Most common case is when you open blue icon (.xcodeproj file) and not the white icon (.xcworkspace file). Remember .xcworkspace file combines your project with Pods and make it complete. Open your project by double clicking the white workspace file and not the blue file.
    – Another cause can be misconfiguration. Discard the content of that folder and start afresh. Unzip your project folder and run pod install while Xcode is closed. Running pod commands while Xcode is open may also cause this error.

Posted in All Tutorials, iOS Tutorials | Tagged | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Powered By: wpnova.com