Xamarin.ios MonoTouch中是否有iOS通知的常量?以及如何获得;“本地”;观察者

Xamarin.ios MonoTouch中是否有iOS通知的常量?以及如何获得;“本地”;观察者,xamarin.ios,Xamarin.ios,我现在正试图弄清楚,如果应用被推到后台,会发送哪个通知字符串。MT中是否有我一直监督的枚举器,或者我真的必须使用字符串,如本例所示: NSNotificationCenter.DefaultCenter.AddObserver ( "UIKeyboardDidShowNotification", MyNotification); 如果没有常量:在哪里可以找到有效字符串?“推送到后台”通知需要哪一个 另一件事:有没有办法让特定的控制器观察员发出通知?在我的示例中,我想去掉控制器当前显示的po

我现在正试图弄清楚,如果应用被推到后台,会发送哪个通知字符串。MT中是否有我一直监督的枚举器,或者我真的必须使用字符串,如本例所示:

NSNotificationCenter.DefaultCenter.AddObserver ( "UIKeyboardDidShowNotification", MyNotification);  
如果没有常量:在哪里可以找到有效字符串?“推送到后台”通知需要哪一个

另一件事:有没有办法让特定的控制器观察员发出通知?在我的示例中,我想去掉控制器当前显示的popover控制器。因此,我希望我的控制器观察通知,而不是采用如上所示的全局方法。
问题是:如果我在我的视图控制器中执行上述操作,移除视图控制器并显示另一个,移除的视图控制器仍然会收到通知。这意味着我不会删除对该控制器的引用。

当然是。我相信这就是你想要的<代码>UIApplicationState.Active

public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
{
    if(application.ApplicationState == UIApplicationState.Active)
    {
        // this means your app is currently in the foreground
    }
    else
    {
        // this means a notification came in when your app was in the background.
    }
}

是的,有常数。您可以在通知引用的类上找到它们作为静态属性。例如,要在应用程序移动到后台时接收通知,可以执行以下操作:

NSObject enterBackgroundObserver;
//...
enterBackgroundObserver = NSNotificationCenter.DefaultCenter.AddObserver (UIApplication.DidEnterBackgroundNotification,
    delegate(NSNotification ntf) {
    Console.WriteLine ("Entered background!");
});
当您不再需要观察者时,不要忘记将其移除:

NSNotificationCenter.DefaultCenter.RemoveObserver (enterBackgroundObserver);

您在哪里重写此方法?UIViewController不提供ReceivedRemoteNotification()。这将在Main.cs的AppDelegate类中。UIViewController不负责直接处理通知。此方法用于接收远程通知。当应用程序从/移动到前台/后台时,不会调用它。您的代码仅在收到远程通知时检查应用程序是在后台还是前台。