How to integrate HockeyApp with Xamarin

Version 5.1.1 (iOS) and 5.2.0 (Android)

If you are targeting iOS: The HockeyApp Xamarin SDK includes the full version of the native HockeySDKs with all features. For iOS, this means that you must include the key NSPhotoLibraryUsageDescription in your app's Info.plist file - otherwise you risk an App Store rejection. Please read up on our blog on the reason behind this change. This does not apply to the iOS CrashOnly variant of SDK, as this is not including the feedback feature.

Introduction

HockeySDK-Xamarin implements support for HockeyApp in your iOS and Android applications.
Please have a look at the native platform SDKs HockeySDK-iOS and HockeySDK-Android for advanced platform-specific behaviors.

The following features are currently supported:

Collect crash reports: If your app crashes, a crash log is written to the device's storage. If the user starts the app again, they will be asked asked to submit the crash report to HockeyApp. This works for both beta and live apps, i.e. those submitted to the App Store. Crash logs contain viable information for you to help resolve the issue. Furthermore, you as a developer can add additional information to the report as well.

Update Ad-Hoc / Enterprise apps: The app will check with HockeyApp if a new version for your Ad-Hoc or Enterprise build is available. If yes, it will show an alert view to the user and let him see the release notes, the version history and start the installation process right away.

Update notification for app store: The app will check if a new version for your app store release is available. If yes, it will show an alert view to the user and let him open your app in the App Store app. (Disabled by default!)

Feedback: Besides crash reports, collecting feedback from your users from within your app is a great option to help with improving your app. You act on and answer feedback directly from the HockeyApp backend.

Authenticate: To help you stay in control of closed tester groups, you can identify and authenticate users against your registered testers with the HockeyApp backend. The authentication feature supports several ways of authentication.

Please make sure to replace $Your_App_Id with the app identifier of your app, otherwise it will not work.

When the app is resumed, the crash manager is triggered and checks if a new crash was created in a previous session. If yes, it presents a dialog to ask the user whether they want to send the crash log to HockeyApp. On app launch the crash manager registers a new exception handler to recognize app crashes.

2.4 Add user metrics

HockeyApp automatically provides you with nice, intelligible, and informative metrics about how your app is used and by whom.

Sessions: A new session is tracked by the SDK whenever the containing app is restarted (this refers to a 'cold start', i.e. when the app has not already been in memory prior to being launched) or whenever it becomes active again after having been in the background for 20 seconds or more.

Users: The SDK anonymously tracks the users of your app by creating a random UUID.

Batching & offline behavior: The SDK batches up to 50 events or waits for 15 seconds and then persists and sends the events, whichever comes first. So for sessions, this might actually mean, we send one single event per batch. If you are sending Custom Events, it can be 1 session event plus X of your Custom Events (up to 50 events per batch total). In case the device is offline, up to 50 batches (of up to 50 events) are stored until the SDK starts to reject and drop new events, logging an error.

For iOS

On iOS, the random UUID ist securely stored in the keychain. On iOS, User Metrics is enabled by default. If you want to turn off User Metrics, please use the following code:

2.6 Add Update Distribution

This will add the in-app update mechanism to your app. Detailed configuration options are in the advanced setup sections for each platform: iOS | Android

For iOS

The feature handles version updates, presents update and version information in an App Store like user interface, collects usage information and provides additional authorization options when using Ad-Hoc provisioning profiles.

To enable automatic in-app updates you need to make sure to add manager.Authenticator.AuthenticateInstallation(); after starting the SDK:

If you want to see beta analytics, use the beta distribution feature with in-app updates and restrict versions to specific users. Or if you want to know who is actually testing your app, follow the instructions on our guide Authenticating Users on iOS.

For Android

Open the activity where you want to inform the user about eventual updates. Typically you want to do this on startup of your main activity.

Add the following code and make sure to always balance register(…) calls to SDK managers with unregister() calls in the corresponding lifecycle callbacks:

When the activity is created, the update manager checks for new updates in the background. If it finds a new update, an alert dialog will be shown. If the user presses Show in said dialog, they will be taken to the update activity. The reason to only do this once upon creation is that the update check causes network traffic and therefore potential costs for your users.

2.7 Add in-app feedback

The feedback manager lets your users communicate directly with you via the app and an integrated user interface. It provides a single threaded discussion with a user running your app. Detailed configuration options are in the advanced setup sections for each platform: iOS | Android

You'll typically only want to show the feedback interface upon user interaction, for this example, we assume you have a button feedbackButton in your view for this.

Add the following lines to your respective view controller/activity, handling the touch events and presenting the feedback interface:

For iOS

You should never create your own instance of BITFeedbackManager but use the one provided by the BITHockeyManager.sharedHockeyManager().

When the user taps on the feedback button, it will launch the feedback interface of the HockeySDK, where the user can create a new feedback discussion, add screenshots or other files for reference, and act on their previous feedback conversations.

3.2 Permissions (Android-Only)

Permissions get automatically merged into your apps manifest. If your app does not use update distribution, you might consider removing the permission WRITE_EXTERNAL_STORAGE - see the advanced permissions section for details.

3.3 Control output to the Console or LogCat

You can control the amount of log messages from HockeySDK that show up in LogCat/the Console. By default, we keep the noise as low as possible, only errors will show up. To enable additional logging, i.e. while debugging, add the following line of code:

3.4 Xamarin.Forms Project Integrate HockeySDK

When adding HockeySDK-Xamarin to a Xamarin.Forms PCL Solution, add the nuget to the PCL, iOS, and Android project (Windows phone is not currently supported).

Initialization must be done in the individual iOS and Android projects as shown in Integrate HockeySDK. The PCL project will have access to a subset of shared non-configuration/initialization features.

Please refer to the Xamarin.Forms sample in /samples/HockeyAppSampleForms.sln.

5. Troubleshooting

Check if "$Your_App_Id" matches the App ID in HockeyApp.

Check if the Package name in Project Options->Android Application file matches the Bundle Identifier of the app in HockeyApp. HockeyApp accepts crashes only if both the App ID and the bundle identifier match their corresponding values in your app. Please note that the package value in your AndroidManifest.xml file might differ from the bundle identifier, this is normal.

If your app crashes and you start it again, does the dialog show up which asks the user to send the crash report? If not, please enable logging.

7. Contributing

7.1 Development Environment

macOS 10.12

Xamarin.Android

Xamarin.iOS

Xcode 9

The file build.cake is the main build script used to compile the SDK source. This script is running on the Cake build system. A bootstrapper.sh file is provided to execute the build without installing cake explicitly.

You can build the source including all samples, nuget packages and components by executing the following command:

sh ./bootstrapper.sh -t all

You can alternatively execute the targets libs, samples, nuget, or components instead of all.

7.2 Code of Conduct

7.3 Contributor license

You must sign a Contributor License Agreement before submitting your pull request. To complete the Contributor License Agreement (CLA), you will need to submit a request via the form and then electronically sign the CLA when you receive the email containing the link to the document. You need to sign the CLA only once to cover submission to any Microsoft OSS project.