2

I am using Hockeyapp to log crashes in my Xamarin application.
For Android I used this code to auto submit crashes with little extra info:
Inside MainActivity OnCreate method:

CrashManager.Register(this, "APP_ID", new CustomCrashListener());

CustomCrashListener:

public class CustomCrashListener : CrashManagerListener
{
    public override bool ShouldAutoUploadCrashes()
    {
        return true;
    }

    public override string UserID => "UserID recovered from settings.";
    public override string Contact => "More info from settings.";
    public override string Description => "Custom Description";
}

Now for the iOS I have found this to auto upload crashes:

Inside AppDelegate:

BITHockeyManager manager = BITHockeyManager.SharedHockeyManager;
manager.Configure("APP_ID");
manager.CrashManager.CrashManagerStatus = BITCrashManagerStatus.AutoSend;
manager.StartManager();
manager.Authenticator.AuthenticateInstallation();

My problem is that I can't find something similar to Android in iOS to send some extra little information with the auto send of crash logs, is there any way to do that in iOS?

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
Paul Karam
  • 4,052
  • 8
  • 30
  • 53

1 Answers1

3

On your UIApplicationDelegate class, add the IBITHockeyManagerDelegate and/or IBITCrashManagerDelegate.

UIApplicationDelegate Example:

[Register("AppDelegate")]
public class AppDelegate : UIApplicationDelegate, IBITHockeyManagerDelegate, IBITCrashManagerDelegate

Assign it to your BITHockeyManager.Delegate:

var hockeyManager = BITHockeyManager.SharedHockeyManager;
hockeyManager.Delegate = (HockeyApp.iOS.BITHockeyManagerDelegate)(IBITHockeyManagerDelegate)this;

Implement which extra info methods you need:

// From IBITHockeyManagerDelegate
[Export("userIDForHockeyManager:componentManager:")]
public string UserIdForHockeyManager(BITHockeyManager hockeyManager, BITHockeyBaseManager componentManager)
{
    return "sushihangover";
}

[Export("userNameForHockeyManager:componentManager:")]
public string UserNameForHockeyManager(BITHockeyManager hockeyManager, BITHockeyBaseManager componentManager)
{
    return "Sushi Hangover";
}

[Export("userEmailForHockeyManager:componentManager:")]
public string UserEmailForHockeyManager(BITHockeyManager hockeyManager, BITHockeyBaseManager componentManager)
{
    return "sushihangover@hacktheplanet.me";
}

// From IBITCrashManagerDelegate
[Export("applicationLogForCrashManager:")]
public string ApplicationLogForCrashManager(BITCrashManager crashManager)
{
    return "StackOverflow rocks...";
}

Ref: https://support.hockeyapp.net/kb/client-integration-ios-mac-os-x-tvos/hockeyapp-for-ios#crashreporting

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • I tried this `hockeyManager.Delegate = (HockeyApp.iOS.BITHockeyManagerDelegate)(IBITHockeyManagerDelegate)this;` but got an invalid cast exception. Then I tried to do safe cast like this `(IBITHockeyManagerDelegate) this as HockeyApp.iOS.BITHockeyManagerDelegate;` but didn't get any information as intended. – Paul Karam Jan 18 '17 at 11:06
  • Note: The delegates are called on the next app start, not at crash time! – Kerni Jan 18 '17 at 11:30
  • @Kerni Yeah, I know this, and I am always launching my application again after the crash to check it on Hokeyapp. – Paul Karam Jan 18 '17 at 11:43
  • I was able to make it work using your answer, but I changed one thing, instead of calling `hockeyManager.Delegate = (HockeyApp.iOS.BITHockeyManagerDelegate)(IBITHockeyManagerDelegate)this;` I added the delegate to the Configure method like this: `manager.Configure(HOCKEYAPP_APP_ID, this);` – Paul Karam Jan 18 '17 at 11:53