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 #209 from Redth/master
Browse files Browse the repository at this point in the history
[HockeyApp] Updated sample and exception handling
  • Loading branch information
dalexsoto committed Apr 18, 2014
2 parents 68499db + e405c9f commit 9f21417
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion HockeyApp/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ASSEMBLY=Card.IO.iOS.dll
ASSEMBLY=HockeyApp.iOS.dll
include ../Rules.make

31 changes: 24 additions & 7 deletions HockeyApp/binding/Additions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Runtime.InteropServices;
using MonoTouch.Foundation;
using MonoTouch.ObjCRuntime;

namespace HockeyApp
{
Expand Down Expand Up @@ -49,16 +50,32 @@ public static void ThrowExceptionAsNative(object exception)
}

[DllImport(MonoTouch.Constants.FoundationLibrary, EntryPoint = "NSGetUncaughtExceptionHandler")]
private static extern IntPtr NSGetUncaughtExceptionHandler();
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);
// 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);
// }

static void ConvertToNsExceptionAndAbort(object e)
{
var name = "Managed Xamarin.iOS .NET Exception";
var msg = e.ToString();

var ex = e as Exception;
if(ex != null)
name = string.Format("{0}: {1}", ex.GetType().FullName, ex.Message);

name = name.Replace("%", "%%");
msg = msg.Replace("%", "%%");
var nse = new NSException(name, msg, null);
var sel = new Selector("raise");
Messaging.void_objc_msgSend(nse.Handle, sel.Handle);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace HockeyAppSampleiOS
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
const string HOCKEYAPP_APPID = "YOUR-HOCKEYAPP-APP-ID";
const string HOCKEYAPP_APPID = "YOUR-HOCKEYAPP-APPID";

UINavigationController navController;
HomeViewController homeViewController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override void ViewDidLoad ()
var hockey = BITHockeyManager.SharedHockeyManager;

Root = new RootElement ("HockeyApp Sample") {
new Section() {
new Section {
new StringElement("Check for Updates", () => {
hockey.UpdateManager.CheckForUpdate();
}),
Expand All @@ -29,9 +29,23 @@ public override void ViewDidLoad ()
hockey.FeedbackManager.ShowFeedbackComposeView();
}),
new StringElement("Crashed Last Run:", hockey.CrashManager.DidCrashInLastSession.ToString())
},
new Section {
new StringElement("Throw Managed .NET Exception", () => {
throw new HockeyAppSampleException("You intentionally caused a crash!");
})
}
};
}
}

public class HockeyAppSampleException : System.Exception
{
public HockeyAppSampleException(string msg) : base(msg)
{
}
}
}

0 comments on commit 9f21417

Please sign in to comment.