如何开始使用MonoTouch的有关我的应用程序通知被关闭/发送到后台? [英] How to get notified with MonoTouch about my application being closed/sent to background?

查看:113
本文介绍了如何开始使用MonoTouch的有关我的应用程序通知被关闭/发送到后台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我觉得这是一个相当琐碎的问题,我找不到任何答案在那里

Although I think this is a fairly trivial question, I could not find any answers out there.

我的问题是:

有没有办法让一个MonoTouch的iPhone应用程序的通知时,我的应用程序被关闭或发送到后台(点击home键的用户)?

Is there a way to get a notification in a MonoTouch iPhone application when my application is being closed or sent to background (by a user clicking the home button)?

我以为 WillTerminate 覆盖好作这一点,但在调试器,它永远不会被调用。

I thought the WillTerminate override was good for this, but in the debugger, it is never called.

推荐答案

有两种方式,当一个应用程序转到得到通知背景:

There are two ways to get notified when an app goes to the background:

一。覆盖适当的方法在你的AppDelegate:

a. Override the appropriate method in your AppDelegate:

public override void DidEnterBackground(UIApplication application)
{
    // App entered background, do some light stuff here, 
    // there is not much time before getting suspended
}

$ b之前多少时间
$ b

乙。通过NSNotificationCenter类新增通知观察家:

b. Add notification observers through the NSNotificationCenter class:

 NSObject observer = NSNotificationCenter.DefaultCenter.AddObserver(
    UIApplication.DidEnterBackgroundNotification, 
    delegate(NSNotification ntf) {

            // Same as above
    });

您可以使用NSObject的对象从的addObserver方法返回删除的观察者,当你不再需要它

You can use the NSObject object returned from the AddObserver method to remove the observer when you no longer need it:

NSNotificationCenter.DefaultCenter.RemoveObserver(observer);

这篇关于如何开始使用MonoTouch的有关我的应用程序通知被关闭/发送到后台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆