- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Cordova 2.1.0 开发 IOS 应用程序。由于我是应用程序开发的新手,所以我有一个非常基本的问题。
我正在使用 applicationDidEnterBackground
方法在应用程序进入后台时处理应用程序控制。但我想了解应用程序进入后台时发送的 UIApplicationDidEnterBackgroundNotification
的实用程序。我可以通过什么方式使用系统发送的此通知和其他通知(如 UIApplicationWillEnterForegroundNotification
等)。这些通知的 USP 是什么。
最佳答案
根据文档,applicationDidEnterBackground:
方法告诉 UIApplication
的委托(delegate)应用程序现在处于后台。在 Cocoa 中,许多委托(delegate)消息都有相应的 UINotification
也被发送。这也不异常(exception)。
根据documentation :
The application also posts a
UIApplicationDidEnterBackgroundNotification
notification around the same time it calls this method to give interested objects a chance to respond to the transition.
因此,如果你的对象图中有对象需要响应状态转换,它们可以观察到这个通知。除了允许图中的所有对象响应应用程序状态转换之外,我不确定是否真的有未说明的目的。我想如果你有一个长时间运行的任务要在应用程序转换到后台任务时执行对象层次结构中的某处,你可以使用 beginBackgroundTaskWithExpirationHandler:
类似于你在 applicationDidEnterBackground 中所做的
。
编辑:
// example, save NSArray *_myArray to disk when app enters background
// this is contrived, and untested, just meant to show how you can
// observe the UIApplicationDidEnterBackgroundNotification and save state
// in an arbitrary point in the object graph. (as opposed, or in addition to, the
// application's delegate.
// long-running tasks, e.g. web service connections, etc. will need to
// get a background task identifier from the UIApplication and manage that.
__block id enteredBackground = nil;
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
enteredBackground = [center addObserverForName:UIApplicationDidEnterBackgroundNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
[_myArray writeToFile:@"/path/to/you/file" atomically:YES];
}];
关于objective-c - 通知实用程序 'UIApplicationDidEnterBackgroundNotification',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12779649/
iPhone 应用程序中 UIApplication DidEnterBackgroundNotification 的用途是什么,或者我们如何从中受益 最佳答案 此通知表示用户在 iPhone 4 上
我正在使用: [[NSNotificationCenter defaultCenter] addObserver:self
在我使用 iOS 9.2、Swift 2.1 的应用程序中,当应用程序进入后台时,我需要将一些数据保存到核心数据中。为此,我在 UIApplicationDidEnterBackgroundNotif
我正在使用 Cordova 2.1.0 开发 IOS 应用程序。由于我是应用程序开发的新手,所以我有一个非常基本的问题。 我正在使用 applicationDidEnterBackground 方法在
我有一个播放音频的 UIView,有一个 NSTimer 和进度条动画。 为简单起见,如果用户切换应用程序或接听电话,我希望所有进程都停止并自行重置。 我建议使用: 调用观察者 - 可能在 viewW
我正在创建播放 youtube 视频的应用。 在这个应用程序中, 用户可以播放 youtube 视频,当用户进入后台或锁定手机时,将播放视频的声音 我正在使用 UIApplicationDidEnte
我将一个文件复制到一个新项目中,它似乎工作正常。这段代码也在旧项目中工作,但突然之间(在新项目中),我遇到了几个我无法弄清楚的错误。 NSNotificationCenter *center = [N
我是一名优秀的程序员,十分优秀!