xcode IOS 调用 didFinishLaunchingWithOptions 时的条件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12599487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Conditions when didFinishLaunchingWithOptions get called by the IOS
提问by clint
Can anybody tell me in what all scenarios does the delegate function didFinishLaunchingWithOptions gets called by the IOS apart from when app is launched for the first time. I launched the app into the device with XCode and removed the connectivity and then tried sending messages to the device through wifi. I then noticed that didFinishLaunchingWithOptions got called few number of times. Why is this happening and what are the conditions when this function gets called. I am not able to figure out all the scenarios. Thanks in advance.
谁能告诉我在所有场景中,除了第一次启动应用程序时,IOS 会调用委托函数 didFinishLaunchingWithOptions 吗?我使用 XCode 将应用程序启动到设备中并删除了连接,然后尝试通过 wifi 向设备发送消息。然后我注意到 didFinishLaunchingWithOptions 被调用了几次。为什么会发生这种情况以及调用此函数时的条件是什么。我无法弄清楚所有场景。提前致谢。
采纳答案by Marco Pace
From Apple documentation:
来自苹果文档:
You should use this method (and the corresponding application:willFinishLaunchingWithOptions: method) to complete your app's initialization and make any final tweaks. This method is called after state restoration has occurred but before your app's window and other UI have been presented. At some point after this method returns, the system calls another of your app delegate's methods to move the app to the active (foreground) state or the background state.
您应该使用此方法(以及相应的 application:willFinishLaunchingWithOptions: 方法)来完成应用程序的初始化并进行任何最终调整。在状态恢复发生后但在您的应用程序的窗口和其他 UI 出现之前调用此方法。在此方法返回后的某个时间点,系统会调用应用程序委托的另一个方法,将应用程序移动到活动(前台)状态或后台状态。
回答by i.AsifNoor
Your question, can anybody tell me in what all scenarios does the delegate function didFinishLaunchingWithOptions gets called by the IOS ?
你的问题,有人能告诉我在所有场景中,IOS 调用了委托函数 didFinishLaunchingWithOptions 吗?
If app is killed or in terminated state and user receives a local notification or remote push notification, and user taps notification, then didFinishLaunchingWithOptions gets called first in both cases.
如果应用程序被终止或处于终止状态并且用户收到本地通知或远程推送通知,并且用户点击通知,则在这两种情况下首先调用 didFinishLaunchingWithOptions。
didFinishLaunchingWithOptions also gets called when you are monitoring location changes using "startMonitoringSignificantLocationChanges". From Apple
当您使用“startMonitoringSignificantLocationChanges”监视位置更改时,也会调用 didFinishLaunchingWithOptions。来自苹果
If you start this service and your app is subsequently terminated, the system automatically relaunches the app into the background if a new event arrives. In such a case, the options dictionary passed to the application(:willFinishLaunchingWithOptions:) and application(:didFinishLaunchingWithOptions:) methods of your app delegate contains the key location to indicate that your app was launched because of a location event.
如果您启动此服务并且您的应用程序随后被终止,则系统会在新事件到达时自动将应用程序重新启动到后台。在这种情况下,传递给应用程序委托的应用程序(:willFinishLaunchingWithOptions :) 和应用程序(:didFinishLaunchingWithOptions :) 方法的选项字典包含关键位置,以指示您的应用程序由于位置事件而启动。
回答by CAMOBAP
This scenarios described in Launch Options Keys
启动选项键中描述的此方案