MvvmCross 升级到 8.x 后,应用程序卡在 SplashScreen
Application get stuck at SplashScreen after MvvmCross upgrade to 8.x
我将所有 MvvmCross 库从 7.1.2 升级到 8.0.0。根据 mvvmcross 文档中的“从 7 升级到 8”教程,我已经实施了必要的更改(覆盖 CreateLogProvider 和 CreateLogFactory 方法并将 iocProvider 作为参数添加到 InitializeFirstChance、InitializeLastChance、InitializeNavigationService 和 CreateApp):
public class Setup : MvxAndroidSetup
{
protected override IMvxAndroidViewPresenter CreateViewPresenter() => new HistoryViewPresenter(ViewAssemblies);
protected override void InitializeFirstChance(IMvxIoCProvider iocProvider)
{
base.InitializeFirstChance(iocProvider);
//Things are done here
}
protected override void InitializeLastChance(IMvxIoCProvider iocProvider)
{
base.InitializeLastChance(iocProvider);
//Things are done here
}
protected override IMvxNavigationService InitializeNavigationService(IMvxIoCProvider iocProvider)
{
var loader = CreateViewModelLoader(iocProvider);
Mvx.IoCProvider.RegisterSingleton<IMvxViewModelLoader>(loader);
InitializeViewDispatcher(iocProvider);
var dispatcher = CreateViewDispatcher();
Mvx.IoCProvider.RegisterSingleton(dispatcher);
var navigationService = new DeepNavigationService(null, loader, dispatcher, iocProvider);
Mvx.IoCProvider.RegisterSingleton<IMvxNavigationService>(navigationService);
return navigationService;
}
//Another things are done here
protected override IMvxApplication CreateApp(IMvxIoCProvider iocProvider)
{
return new App();
}
protected override ILoggerProvider CreateLogProvider()
{
return new SerilogLoggerProvider();
}
protected override ILoggerFactory CreateLogFactory()
{
Serilog.Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.CreateLogger();
return new SerilogLoggerFactory();
}
}
我还在 Core 项目中创建了自定义应用启动并设置了这个 class RegisterCustomAppStart:
public class AppStart : MvxAppStart
{
public AppStart(IMvxApplication application, IMvxNavigationService navigationService) : base(application, navigationService) { }
protected override Task NavigateToFirstViewModel(object hint = null)
{
return NavigationService.Navigate<StartupViewModel>();
}
}
public class App : MvxApplication
{
public override void Initialize()
{
//Services and Singletons are registered here.
RegisterCustomAppStart<AppStart>();
}
}
这就是问题 - 当我 运行 应用程序时,我的应用程序卡在了 SplashScreen 中。有人遇到过类似的问题吗?在以前的版本中,一切都很好。如果能提供一些解决方法的建议,我将不胜感激
我解决了这个问题 - 我更改了行:
var dispatcher = CreateViewDispatcher();
对于:
var dispatcher = Mvx.IoCProvider.Resolve<IMvxViewDispatcher>();
而且有效。
我将所有 MvvmCross 库从 7.1.2 升级到 8.0.0。根据 mvvmcross 文档中的“从 7 升级到 8”教程,我已经实施了必要的更改(覆盖 CreateLogProvider 和 CreateLogFactory 方法并将 iocProvider 作为参数添加到 InitializeFirstChance、InitializeLastChance、InitializeNavigationService 和 CreateApp):
public class Setup : MvxAndroidSetup
{
protected override IMvxAndroidViewPresenter CreateViewPresenter() => new HistoryViewPresenter(ViewAssemblies);
protected override void InitializeFirstChance(IMvxIoCProvider iocProvider)
{
base.InitializeFirstChance(iocProvider);
//Things are done here
}
protected override void InitializeLastChance(IMvxIoCProvider iocProvider)
{
base.InitializeLastChance(iocProvider);
//Things are done here
}
protected override IMvxNavigationService InitializeNavigationService(IMvxIoCProvider iocProvider)
{
var loader = CreateViewModelLoader(iocProvider);
Mvx.IoCProvider.RegisterSingleton<IMvxViewModelLoader>(loader);
InitializeViewDispatcher(iocProvider);
var dispatcher = CreateViewDispatcher();
Mvx.IoCProvider.RegisterSingleton(dispatcher);
var navigationService = new DeepNavigationService(null, loader, dispatcher, iocProvider);
Mvx.IoCProvider.RegisterSingleton<IMvxNavigationService>(navigationService);
return navigationService;
}
//Another things are done here
protected override IMvxApplication CreateApp(IMvxIoCProvider iocProvider)
{
return new App();
}
protected override ILoggerProvider CreateLogProvider()
{
return new SerilogLoggerProvider();
}
protected override ILoggerFactory CreateLogFactory()
{
Serilog.Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.CreateLogger();
return new SerilogLoggerFactory();
}
}
我还在 Core 项目中创建了自定义应用启动并设置了这个 class RegisterCustomAppStart:
public class AppStart : MvxAppStart
{
public AppStart(IMvxApplication application, IMvxNavigationService navigationService) : base(application, navigationService) { }
protected override Task NavigateToFirstViewModel(object hint = null)
{
return NavigationService.Navigate<StartupViewModel>();
}
}
public class App : MvxApplication
{
public override void Initialize()
{
//Services and Singletons are registered here.
RegisterCustomAppStart<AppStart>();
}
}
这就是问题 - 当我 运行 应用程序时,我的应用程序卡在了 SplashScreen 中。有人遇到过类似的问题吗?在以前的版本中,一切都很好。如果能提供一些解决方法的建议,我将不胜感激
我解决了这个问题 - 我更改了行:
var dispatcher = CreateViewDispatcher();
对于:
var dispatcher = Mvx.IoCProvider.Resolve<IMvxViewDispatcher>();
而且有效。