我正在使用LocalNotification插件(nuget)生成电话 事件通知,效果很好。如果用户导航到 列出通知并选择一个通知的页面,然后转到 NotificationPageModel.cs页面。他们从那里按下一个按钮 将其导航开,只要手动导航即可
如果用户单击电话的通知 (app.xaml.cs:OnLocalNotificationTapped)然后尝试导航时 会生成一个FreshTinyIoC.TinyIoCResolutionException。
当用户点击“
通知(masterDetailNav.Navigation.PushModalAsync(npage);
)吗?
相关版本:Xamarin.Forms v3.6.0.264807 FreshMvvm v3.0.0 Thudugala v4.0.5的Plugin.LocalNotification
App.xaml.cs
void OnLocalNotificationTapped(NotificationTappedEventArgs e)
{
var _logger = FreshMvvm.FreshIOC.Container.Resolve<ILoggingService>();
_logger.Info("Pressed notification: {0}", e.Data);
Notification notification = new Notification();
if (string.IsNullOrWhiteSpace(e.Data))
{
return;
}
else
{
notification = JsonConvert.DeserializeObject<Notification>(e.Data);
}
//CoreMethods.PushPageModel<NotificationPageModel>(notification); //cant find coremethods
var npage = FreshPageModelResolver.ResolvePageModel<NotificationPageModel>(notification);
masterDetailNav.Navigation.PushModalAsync(npage);
}
NotificationPageModel.cs:
public async void Cancel()
{
_logger.Info("Notification {0} Cancel: {1}", Notification.Gateway, Notification.TimeStamp);
//Navigate away from page
//await CoreMethods.PopPageModel(); //this only works if manually navigated to
//attempt #1
await CoreMethods.PushPageModel<HomePageModel>();
}
public async void Remove()
{
_logger.Info("Notification {0} Remove: {1}", Notification.Gateway, Notification.TimeStamp);
//Remove notification
try
{
_user.Notifications.Remove(Notification);
}
catch (Exception ex)
{
_logger.Warn("Remove Notification: {0}", ex.Message);
}
//Navigate away from page
//await CoreMethods.PopPageModel(); //this only works if manually navigated to
//attempt #2
var hpage = FreshPageModelResolver.ResolvePageModel<HomePageModel>();
await CoreMethods.PushPageModelWithNewNavigation<HomePageModel>(hpage);
}
Stacktrace
FreshTinyIoC.TinyIoCResolutionException消息=解析失败: IFreshNavigationService Source = mscorlib StackTrace:在 FreshTinyIoC.FreshTinyIoCContainer.ResolveInternal (FreshTinyIoC.FreshTinyIoCContainer + TypeRegistration注册, FreshTinyIoC.NamedParameterOverloads参数, FreshTinyIoC.ResolveOptions选项)[0x000f7]在 C:\ Projects \ FreshMvvm \ src \ FreshIOC \ FreshTinyIOC.cs:3142 at FreshTinyIoC.FreshTinyIoCContainer.Resolve(System.Type resolveType, System.String名称)[0x00000]在 C:\ Projects \ FreshMvvm \ src \ FreshIOC \ FreshTinyIOC.cs:1211 at FreshTinyIoC.FreshTinyIoCContainer.Resolve [ResolveType](System.String 名称)[0x00000]在 C:\ Projects \ FreshMvvm \ src \ FreshIOC \ FreshTinyIOC.cs:1332位于 FreshMvvm.FreshTinyIOCBuiltIn.Resolve [ResolveType](System.String 名称)[0x00000]在 C:\ Projects \ FreshMvvm \ src \ FreshMvvm \ FreshTinyIOCBuiltIn.cs:31 at FreshMvvm.PageModelCoreMethods.PushNewNavigationServiceModal (FreshMvvm.IFreshNavigationService newNavigationService, FreshMvvm.FreshBasePageModel [] basePageModels,System.Boolean动画) [0x00073]在 C:\ Projects \ FreshMvvm \ src \ FreshMvvm \ PageModelCoreMethods.cs:178 at FreshMvvm.PageModelCoreMethods.PushPageModelWithNewNavigation [T] (System.Object数据,System.Boolean动画)[0x00060]在 C:\ Projects \ FreshMvvm \ src \ FreshMvvm \ PageModelCoreMethods.cs:235 at cdaxrobot.PageModels.NotificationPageModel.Go()[0x00225]在 C:\ Work \ RobotApp \ App \ cdaxrobot \ cdaxrobot \ cdaxrobot \ PageModels \ NotificationPageModel.cs:113 在 System.Runtime.CompilerServices.AsyncMethodBuilderCore + <> c.b__7_0 (系统对象状态)在[0x00000]中 /Users/builder/jenkins/workspace/archive-mono/2019-08/android/release/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 在Android.App.SyncContext + <> c__DisplayClass2_0.b__0() 在<11f101b564894ca7af6c482ddc51c698>:0中的[0x00000] Java.Lang.Thread + RunnableImplementor.Run()[0x00008]在 <11f101b564894ca7af6c482ddc51c698>:0在 Java.Lang.IRunnableInvoker.n_Run(System.IntPtr jnienv,System.IntPtr native_this)[0x00009]在<11f101b564894ca7af6c482ddc51c698>:0中 (包装器动态方法) Android.Runtime.DynamicMethodNameCounter.41(intptr,intptr)
答案 0 :(得分:0)
感谢您的回复。 我设法通过创建一个新的NavigationContainer对其进行了修复:
notificationPage = FreshMvvm.FreshPageModelResolver.ResolvePageModel<NotificationPageModel>(true);
notificationContainer = new FreshNavigationContainer(notificationPage, Models.Constants.NotificationContainer);
void OnLocalNotificationTapped(NotificationTappedEventArgs e)
{
MainPage = notificationContainer;
}
然后在页面中执行以下操作:
if (CameFromNotification == true)
{
_logger.Debug("Navigating back to MainContainer");
CoreMethods.SwitchOutRootNavigation(Models.Constants.MainContainer);
}
else
{
_logger.Debug("Navigating by popping the stack");
await CoreMethods.PopPageModel();
}