更新时间:2023-01-25 22:06:57
步骤1:
当应用程序启动并且之前不在后台(挂起)时,application:didFinishLaunchingWithOptions:
将首先执行.此方法带有launchOptions
参数-当它为nil
时,则通过Springboard中的图标点击启动您的应用.否则,launchOptions
将指示启动应用程序的原因(URL方案,推送通知等...更多信息,位于
Step 1:
When application is started and wasn't in the background before (suspended), application:didFinishLaunchingWithOptions:
will execute first. This method carries launchOptions
parameter - when it's nil
, then your app was launched via icon tap in Springboard. Otherwise launchOptions
will indicate the reason app was started (URL-scheme, Push Notification etc... more in documentation).
第2步:
到目前为止,一切都很好.现在,让我们开始恢复.恢复(或启动)应用程序时,它有时会在应用程序的委托中调用applicationDidBecomeActive
.诀窍是,在可以恢复(启动)应用程序的所有可能原因后,将调用此方法.因此,您需要做的就是引入一个BOOL
标志,您将在服务恢复应用程序原因的方法中设置该标志,并稍后在applicationDidBecomeActive
中将其与期望值进行比较.
Step 2:
So far, so good. Now let's take care of resuming. When an app is resumed (or started), at some point it will call applicationDidBecomeActive
in app's delegate. The trick is that this method is called after all possible reasons due to application can be resumed (started) were serviced. So all you need to do is introduce a BOOL
flag that you'll set in methods servicing the reason your app was resumed and check it later in applicationDidBecomeActive
against expected value.
需要设置标志的方法列表(我想是不完整的):
A list (incomplete, I guess) of methods where your flag needs to be set:
application:handleOpenURL:
application:openURL:sourceApplication:annotation:
application:didReceiveLocalNotification:
application:didReceiveRemoteNotification:
application:handleOpenURL:
application:openURL:sourceApplication:annotation:
application:didReceiveLocalNotification:
application:didReceiveRemoteNotification:
The rest of methods you'll find in documentation mentioned above. And remember that applicationDidBecomeActive
for Step 1 will also be called.
祝你好运!