OStack程序员社区-中国程序员成长平台

标题: ios - 如何在 Xamarin.iOS 中将崩溃日志自动发送到 HokeyApp 并提供额外信息? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 12:46
标题: ios - 如何在 Xamarin.iOS 中将崩溃日志自动发送到 HokeyApp 并提供额外信息?

我正在使用 Hockeyapp 在我的 Xamarin 应用程序中记录崩溃。
对于 Android,我使用此代码自动提交崩溃,并提供很少的额外信息:
MainActivity OnCreate 方法内部:

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";
}

现在对于 iOS,我发现这是自动上传崩溃:

AppDelegate 内部:

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

我的问题是我在 iOS 中找不到类似于 Android 的东西来通过自动发送崩溃日志来发送一些额外的小信息,在 iOS 中有什么方法可以做到这一点?



Best Answer-推荐答案


在您的 UIApplicationDelegate 类中,添加 IBITHockeyManagerDelegate 和/或 IBITCrashManagerDelegate

UIApplicationDelegate 示例:

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

将其分配给您的 BITHockeyManager.Delegate:

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

实现你需要的extra info方法:

// 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 "[email protected]";
}

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

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

关于ios - 如何在 Xamarin.iOS 中将崩溃日志自动发送到 HokeyApp 并提供额外信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41714627/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4