How to get Crash logs from your iOS application installed in user’s device.?

Errors can happen to anyone even if it is a developer or theCEO of the company. Most of us know how important are the crash reports. As a beginner, if you have already uploaded apps to the Play store or Appstore and you have no idea how to get the crash logs from the user’s device, be patience, I will show you how to do it.

Getting the error details from the user’s device without annoying the user. That is what Crash report is all about.

I would like to share the some thoughts about google’s firebase. It’s a great product for mobile application developers.

 

FireBase

Firebase is basically a cloud service provider. It provides lots of free and paid features such as App Analytics, Storage, Realtime Database, Authentication, Cloud Messaging, Crash Reporting and etc…

In your firebase free tier account you will get these benefits,

  1. Firebase provides App Analytics and Crash Reporting  as a free too for all the users.
  2. You can host up to 5GB data in your free tier account.
  3. 1GB database is free database storage.
  4. You can host your static website and contents. You will have 1GB space for this.

 

Unfortunately you cannot run your server side code there.

 

Lets go through Crash reporting and its configurations step by step.

 

  • Create a Xcode project and name it as CrashHandlers.
  • You have to register an account in firebase.
  • Goto console
  • Create a new cloud project and name it as MyTestCrashHandling.
  • Fill the necessary fields and initiate the cloud project.

initiate-the-firebase-ios-project

  • Download the configuration file from console. (GoogleService-Info.plist)
  • Add that to your xcode project.

add-googleservice-info-plist

 

 

 

 

Add firebase sdk and set up Crash Reporting to the xcode project

  • Open the terminal and do the following steps carefully.

[code]

$ cd  CrashHandlers-project-directory
$ pod init

[/code]

 

There will be a [code]Podfile[/code] generated.

 

add the following pods,

 

[code]

pod ‘Firebase/Core’
pod ‘Firebase/Crash’

[/code]

 

Install the pods and open the [code].xcworkspace[/code] file to see the project in Xcode. see below

 

[code]

$ pod install
$ open CrashHandlers-project.xcworkspace

[/code]

 

 

 

Generate service account key file from firebase console

In order to authenticate your file uploads You have to create service account key

  1. Goto console
  2. Goto Permissions page like below

Add image here….

firebase_xcode_adding_permission

 

3. Goto Service Accounts tab and create a new Service Accounts like below,

 

firebase-create-service-account

 

 

 

 

 

 

 

 

create-service-accounts

 

  • You willbe prompted to download the json key file (MyTestCrashHandling-f9b0e09b6a42.json) and save it in your project folder.

Add an upload script for your symbol files

  • Open your xcode project and select target as project

 

xcode-select-target-project

 

  • Goto Build Phases, Like below click `+` to add  Run Script  phase

 

xcode-select-run-phase

 

  • Add the following contents

[code]

# Get the GOOGLE_APP_ID from your GoogleService-Info.plist file
GOOGLE_APP_ID=1:my:app:id

# Replace the path with the path to the key you just downloaded
"${PODS_ROOT}"/FirebaseCrash/upload-sym "ServiceAccount.json path"

[/code]

 

add-run-script-to-xcode-project

 

Thats all, Now go to AppDelegate’s [code]didFinishLaunchingWithOptions[/code] method and initiate the firebase and throw an exception. See below.

 

xcode-example-appdelegate-file-with-firebase-config

 

Now build the app and run with your device or simulator. Debugger will not allow you to run your application due to the fatal error.

Stop your app and run your app manually (By clicking on the app)

Now you will notice app will crash and shutdown.

comment the [code]fatalError()[/code] call in the [code]didFinishLaunchingWithOptions[/code] method.

Now run your app again. You can notice the error log has uploaded successfully.

 

crash-log-uploaded-successfully-to-firebase-server

 

Goto firebase console and open the project. You will notice the changes. i will add you some of my firebase console images.

 

firebase-error-log-uploaded-1

 

firebase-error-log-uploaded-2

 

firebase-error-log-uploaded-3

 

If you have missed any of the above steps, you will not get the result. Keep following with the next blog. Please let me know if you need any help.

 

Thank you very much.

 

 

Add a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.