Xamarin 找出应用程序在启动时崩溃的原因的最佳方法是什么?
我现在遇到了一个问题:当我开始调试时,应用程序直接崩溃,调试过程停止。我看不到任何日志或错误消息。我不知道在这种情况下我能做什么 我试图把-v-v-v-v添加到附加的mtouch参数中。但在应用程序停止调试时,没有看到任何打印输出 有没有办法解决这个问题 致意Xamarin 找出应用程序在启动时崩溃的原因的最佳方法是什么?,xamarin,xamarin.forms,xamarin.ios,crash,Xamarin,Xamarin.forms,Xamarin.ios,Crash,我现在遇到了一个问题:当我开始调试时,应用程序直接崩溃,调试过程停止。我看不到任何日志或错误消息。我不知道在这种情况下我能做什么 我试图把-v-v-v-v添加到附加的mtouch参数中。但在应用程序停止调试时,没有看到任何打印输出 有没有办法解决这个问题 致意 Lin您应该尝试捕获这样的未处理异常 public override bool FinishedLaunching(UIApplication app, NSDictionary options) {
Lin您应该尝试捕获这样的未处理异常
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;
...
#region Error handling
private void TaskSchedulerOnUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
var newExc = new Exception("TaskSchedulerOnUnobservedTaskException", e.Exception);
LogUnhandledException(newExc);
}
private void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var newExc = new Exception("CurrentDomainOnUnhandledException", e.ExceptionObject as Exception);
LogUnhandledException(newExc);
}
internal static void LogUnhandledException(Exception exception)
{
try
{
const string errorFileName = "Fatal.log";
var libraryPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Resources); // iOS: Environment.SpecialFolder.Resources
var errorFilePath = Path.Combine(libraryPath, errorFileName);
var errorMessage = string.Format("Time: {0}\r\nError: Unhandled Exception\r\n{1}",
DateTime.Now, exception.ToString());
File.WriteAllText(errorFilePath, errorMessage);
}
catch
{
// just suppress any error logging exceptions
}
}
// If there is an unhandled exception, the exception information is diplayed
// on screen the next time the app is started (only in debug configuration)
[Conditional("DEBUG")]
private static void DisplayCrashReport()
{
const string errorFilename = "Fatal.log";
var libraryPath = Environment.GetFolderPath(Environment.SpecialFolder.Resources);
var errorFilePath = Path.Combine(libraryPath, errorFilename);
if (!File.Exists(errorFilePath))
{
return;
}
var errorText = File.ReadAllText(errorFilePath);
var alertView = new UIAlertView("Crash Report", errorText, null, "Close", "Clear") { UserInteractionEnabled = true };
alertView.Clicked += (sender, args) =>
{
if (args.ButtonIndex != 0)
{
File.Delete(errorFilePath);
}
};
alertView.Show();
}
#endregion
public override bool FinishedLaunching(UIApplication应用程序、NSDictionary选项)
{
AppDomain.CurrentDomain.UnhandledException+=CurrentDomainOnUnhandledException;
TaskScheduler.UnobservedTaskeException+=TaskScheduleRonUnobservedTaskeException;
全局::Xamarin.Forms.Forms.Init();
全局::XamForms.Controls.iOS.Calendar.Init();
global::ZXing.Net.Mobile.Forms.iOS.Platform.Init();
Firebase.Core.App.Configure();
Messaging.SharedInstance.Delegate=此;
DependencyService.Register();
DependencyService.Register();
加载应用程序(新应用程序());
InstanceId.Notifications.ObserveTokenRefresh(令牌刷新通知);
if(UIDevice.CurrentDevice.CheckSystemVersion(10,0))
{
//iOS 10或更高版本
var authOptions=未授权选项。警报|未授权选项。徽章|未授权选项。声音;
UnuseNotificationCenter.Current.RequestAuthorization(authOptions,(已授予,错误)=>{
控制台写入线(已授予);
});
//对于iOS 10显示通知(通过APNS发送)
UNUserNotificationCenter.Current.Delegate=此;
//对于iOS 10数据消息(通过FCM发送)
//Messaging.SharedInstance.RemoteMessageDelegate=此;
}
其他的
{
//iOS 9或之前
var allNotificationTypes=UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
var settings=UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes,null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(设置);
}
UIApplication.SharedApplication.RegisterForRemotonifications();
UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert,(已批准,错误)=>{
//办理审批
});
UNUserNotificationCenter.Current.GetNotificationSettings((设置)=>{
var alertsallow=(settings.AlertSetting==UNNotificationSetting.Enabled);
});
返回基地。完成发射(应用程序,选项);
}
查看XcodeAppcenter中的设备日志。Crashes@Jason嗨,杰森,谢谢你的评论。我正在使用VS for MAC,我在这里找到了设备日志,但是这里列出的错误让我很难理解。我用我的项目名称作为关键词进行搜索。可以看到两个相关错误:1。错误(54)/SpringBoard(FrontBoard):忽略未跟踪进程的状态[应用程序:1125]*:2。错误(54)/SpringBoard(UserNotificationsServer):[ch.usz.jumpinE]遇到与nil环境的推送注册,将不会使令牌无效。谷歌搜索,但没有有用的信息。非常感谢你的代码。但它在它之前就崩溃了。我在第一行设置了断点,但应用程序崩溃并且没有达到断点。我应该只共享FinishedLaunching吗?public override bool FinishedLaunching(UIApplication app,NSDictionary选项){AppDomain.CurrentDomain.UnhandledException+=CurrentDomainOnUnhandledException;TaskScheduler.UnobservedTaskeException+=TaskScheduleRonUnobservedTaskeException;global::Xamarin.Forms.Forms.Init();…我的应用程序在启动屏幕后崩溃,它尚未输入此代码。
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;
global::Xamarin.Forms.Forms.Init();
global::XamForms.Controls.iOS.Calendar.Init();
global::ZXing.Net.Mobile.Forms.iOS.Platform.Init();
Firebase.Core.App.Configure();
Messaging.SharedInstance.Delegate = this;
DependencyService.Register<IJumpinNotificationService, JumpinNotificationService>();
DependencyService.Register<IJumpinPublicKeyValidateService, JumpinPublicKeyValidateService>();
LoadApplication(new App());
InstanceId.Notifications.ObserveTokenRefresh(TokenRefreshNotification);
if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
{
// iOS 10 or later
var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) => {
Console.WriteLine(granted);
});
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.Current.Delegate = this;
// For iOS 10 data message (sent via FCM)
//Messaging.SharedInstance.RemoteMessageDelegate = this;
}
else
{
// iOS 9 or before
var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
}
UIApplication.SharedApplication.RegisterForRemoteNotifications();
UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert, (approved, err) => {
// Handle approval
});
UNUserNotificationCenter.Current.GetNotificationSettings((settings) => {
var alertsAllowed = (settings.AlertSetting == UNNotificationSetting.Enabled);
});
return base.FinishedLaunching(app, options);
}