Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #207 from Redth/master
Browse files Browse the repository at this point in the history
[HockeyApp] Added ability to throw .NET exceptions as native iOS exceptions
  • Loading branch information
dalexsoto committed Apr 14, 2014
2 parents bbd2838 + cb8470b commit 8e19faa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
24 changes: 24 additions & 0 deletions HockeyApp/binding/Additions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Runtime.InteropServices;
using MonoTouch.Foundation;

namespace HockeyApp
{
Expand Down Expand Up @@ -36,6 +37,29 @@ public static void EnableCustomCrashReporting (Action customCrashReportingEnable
Marshal.FreeHGlobal (sigbus);
Marshal.FreeHGlobal (sigsegv);
}

public static void ThrowExceptionAsNative(Exception exception)
{
ConvertToNsExceptionAndAbort (exception);
}

public static void ThrowExceptionAsNative(object exception)
{
ConvertToNsExceptionAndAbort (exception);
}

[DllImport(MonoTouch.Constants.FoundationLibrary, EntryPoint = "NSGetUncaughtExceptionHandler")]
private static extern IntPtr NSGetUncaughtExceptionHandler();

private delegate void ReporterDelegate(IntPtr ex);

private static void ConvertToNsExceptionAndAbort(object e)
{
var nse = new NSException(".NET Exception", e.ToString(), null);
var uncaught = NSGetUncaughtExceptionHandler();
var dele = (ReporterDelegate)Marshal.GetDelegateForFunctionPointer(uncaught, typeof(ReporterDelegate));
dele(nse.Handle);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using HockeyApp;
using System.Threading.Tasks;

namespace HockeyAppSampleiOS
{
Expand All @@ -13,23 +14,15 @@ namespace HockeyAppSampleiOS
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
const string HOCKEYAPP_APPID = "c504052380d242a3c72b2878de7dd472";
const string HOCKEYAPP_APPID = "YOUR-HOCKEYAPP-APP-ID";

UINavigationController navController;
HomeViewController homeViewController;
// class-level declarations
UIWindow window;
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{

HockeyApp.Setup.EnableCustomCrashReporting (() => {
Setup.EnableCustomCrashReporting (() => {
//Get the shared instance
var manager = BITHockeyManager.SharedHockeyManager;
Expand All @@ -42,14 +35,21 @@ public override bool FinishedLaunching (UIApplication app, NSDictionary options)
//Authenticate (there are other authentication options)
manager.Authenticator.AuthenticateInstallation ();
//Rethrow any unhandled .NET exceptions as native iOS
// exceptions so the stack traces appear nicely in HockeyApp
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
Setup.ThrowExceptionAsNative(e.ExceptionObject);
TaskScheduler.UnobservedTaskException += (sender, e) =>
Setup.ThrowExceptionAsNative(e.Exception);
});

// create a new window instance based on the screen size
window = new UIWindow (UIScreen.MainScreen.Bounds);

homeViewController = new HomeViewController ();
navController = new UINavigationController (homeViewController);
// If you have defined a root view controller, set it here:
window.RootViewController = navController;

// make the window visible
Expand Down

0 comments on commit 8e19faa

Please sign in to comment.