application:didFinishLaunchingWithOptions:

本文详细介绍了iOS应用中的`application:didFinishLaunchingWithOptions:`方法,包括其作用、参数解释、返回值意义及应用初始化的最佳实践。该方法在启动过程中调用,用于完成初始化工作和最后的UI调整,是处理启动选项的关键时机。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

application:didFinishLaunchingWithOptions:


Tells the delegate that the launch process is almost done and the app is almost ready to run.

(告诉delegate启动进程即将完成,应用程序即将开始运行)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Parameters

application

The singleton app object.

(单例应用程序对象)

launchOptions

A dictionary indicating the reason the app was launched (if any). The contents of this dictionary may be empty in situations where the user launched the app directly. For information about the possible keys in this dictionary and how to handle them, see “Launch Options Keys.”

(一个用来表示应用程序启动原因的数据字典,不是必需的。如果用户直接启动这个应用程序,launchOptions会是空值。请参考“Launch Options Keys.”,来进一步了解这个数据字典里会有什么样的关键字,以及如何处理它们)

Return Value

NO if the app cannot handle the URL resource, otherwise return YES. The return value is ignored if the app is launched as a result of a remote notification.

(如果应用程序不处理URL 资源,返回NO;否则,返回YES.如果应用程序有一个远程通知启动,返回值会被忽略)

Discussion

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元素还没有被呈现出来。有时应用程序从这个方法返回后,系统会调用delegage的其他方法来将应用程序值为active (foreground状态),或者background状态)

This method represents your last chance to process any keys in the launchOptions dictionary. If you did not evaluate the keys in your application:willFinishLaunchingWithOptions: method, you should look at them in this method and provide an appropriate response.

(如果你不在这个方法里处理launchOptions,你将没有机会再一次处理他们。如果你不在application:willFinishLaunchingWithOptions: 里处理launchOptinons,你还可以在这个方法里处理,并给出相应的反馈。)

Objects that are not the app delegate can access the same launchOptions dictionary values by observing the notification named UIApplicationDidFinishLaunchingNotification and accessing the notification’s userInfo dictionary. That notification is sent shortly after this method returns.

(应用程序delegate以外的其他对象可以通过处理UIApplicationDidFinishLaunchingNotification通知来访问launchOptions数据字典的userInfo信息,这个方法返回后,很快会发送UIApplicationDidFinishLaunchingNotification通知

Important: For app initialization, it is highly recommended that you use this method and the application:willFinishLaunchingWithOptions: method and do not use the applicationDidFinishLaunching: method, which is intended only for apps that run on older versions of iOS.

(重点:强烈建议使用这个方法或者:willFinishLaunchingWithOptions: method来实现应用程序初始化的工作。不要使用applicationDidFinishLaunching:,这个方法只使用在旧版本的iOS应用程序中)


The return result from this method is combined with the return result from the application:willFinishLaunchingWithOptions: method to determine if a URL should be handled. If either method returns NO, the URL is not handled. If you do not implement one of the methods, only the return value of the implemented method is considered.

(应用程序结合这个方法的返回值和willFinishLaunchingWithOptions: 返回值来共同决定是否处理URL,两者中任意一个返回NO,就不处理URL.If you do not implement one of the methods, only the return value of the implemented method is considered.)

Availability

  • Available in iOS 3.0 and later.

See Also

  • – application:willFinishLaunchingWithOptions:
  • – applicationDidBecomeActive:
  • – applicationDidEnterBackground:

Declared In

UIApplication.h

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值