ios - didFinishLaunchingWithOptions 后台恢复或完全启动

标签 ios

didFinishLaunchingWithOptions 中,您如何知道应用程序是从前台恢复还是新启动?我需要知道这个方法,因为有 2 个任务要运行,具体取决于 launchOptions 是什么以及应用程序处于什么状态。谢谢。

最佳答案

来自 Test if app did become active from a UILocalNotification :

When an app enters the foreground from the background it does not trigger applicationDidFinishLaunchingWithOptions. It does, however, call applicationWillEnterForeground and applicationDidBecomeActive. This can be verified with a couple of NSLogs.

因此可以知道应用程序是从后台返回还是新启动。


来自 the developer page :搜索 didFinishLaunchingWithOptions,您将拥有所有选项。此外,他们有这张图表告诉应用程序具有的所有阶段:

State changes in an iOS app

您正在寻找的是 Inactive 状态:

The app is running in the foreground but is not receiving events. (It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state. Upon entering this state, the app should put itself into a quiescent state with the expectation of moving to the background or active state shortly.

或暂停状态:

The app is in memory but is not executing code. The system suspends apps that are in the background and do not have any pending tasks to complete. The system may purge suspended apps at any time without waking them up to make room for other apps.

看完这篇我不认为你需要的是背景状态

关于ios - didFinishLaunchingWithOptions 后台恢复或完全启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34728354/

相关文章:

ios - 核心文本 : Invalid 'kern' Subtable In CTFont

iphone - IOS Urban Airship 。如何处理通知

ios - 更改 UIPickerView 中文本的高度?

objective-c - iOS - 跨 Storyboard使用的 NIB View (用于设计和动画逻辑)

ios - 如何找到 Xcode 10.1 的 ImageView

ios - 将 UITableViewCell 的背景颜色设置为图案图像

ios - IOS 应用的 swift 解析

ios - 在 UITableView 中单击单元格按钮时模糊单元格图像

ios - 呈现 UIAlertController (以操作表样式)导致神秘的自动布局警告

ios - 如何将特定字符串替换为 NSTextAttachment 以显示图像