xamarin.forms检测从后台进入前台的ios应用程序

xamarin.forms检测从后台进入前台的ios应用程序,xamarin.forms,xamarin.ios,Xamarin.forms,Xamarin.ios,我正在Xamarin.Formsshared proeject中创建应用程序。我想检测来自后台的应用程序 目前,我已经在AppDelegate中实现了OnActivated方法,但在iphone中打开control center时也会调用此方法。当应用程序从后台进入前台时,我希望我的应用程序重新连接到服务器,并相应地显示消息,但当我向上滑动并打开control center时,也会显示此消息 在nativeXamarin.iOSapp中,有一个方法WillEnterForegroundNotif

我正在
Xamarin.Forms
shared proeject中创建应用程序。我想检测来自后台的应用程序

目前,我已经在
AppDelegate
中实现了
OnActivated
方法,但在iphone中打开control center时也会调用此方法。当应用程序从后台进入前台时,我希望我的应用程序重新连接到服务器,并相应地显示消息,但当我向上滑动并打开control center时,也会显示此消息

在native
Xamarin.iOS
app中,有一个方法
WillEnterForegroundNotification
,但此方法在此处不可用


是否只有当应用程序来自后台时才调用任何方法?
app.xaml.cs

protected override void OnResume()
在原生Xamarin.iOS应用程序中,有一个方法 WillEnterForegroundNotification,但此方法在此处不可用

您可以访问Xamarin.forms项目中的
WillEnterForegroundNotification
方法,只需在
AppDelegate.cs
中重写它:

public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
    //
    // This method is invoked when the application has loaded and is ready to run. In this 
    // method you should instantiate the window, load the UI into it and then make the window
    // visible.
    //
    // You have 17 seconds to return from this method, or iOS will terminate your application.
    //
    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        global::Xamarin.Forms.Forms.Init();
        LoadApplication(new App());

        return base.FinishedLaunching(app, options);
    }

    public override void WillEnterForeground(UIApplication uiApplication)
    {   
        //handle your event here 
        base.WillEnterForeground(uiApplication);
    }
} 

您是否尝试过在您的
AppDelegate
中重写
public override void WillEnterForeground(UIApplication UIApplication)
?感谢您的评论,同样的行为也会发生在
OnResume
中。即使我尝试更改wifi或播放一些音乐(控制中心),我也会使用Xamarin.Forms.MessagingCenter在“OnResume”期间广播活动,并在需要处理活动的任何地方订阅。