2.1UIApplicationDelegate官方说明

2.1UIApplicationDelegate官方说明

The UIApplicationDelegate protocol defines methods that are called by the singleton UIApplication object in response to important events in the lifetime of your app.

在你的应用程序生命周期内,单例的UIApplication对象在响应系统最重要事件的时候UIApplicationDelegate协议定义的方法就会被调用.

The app delegate works alongside the app object to ensure your app interacts properly with the system and with other apps. Specifically, the methods of the app delegate give you a chance to respond to important changes. For example, you use the methods of the app delegate to respond to state transitions, such as when your app moves from foreground to background execution, and to respond to incoming notifications. In many cases, the methods of the app delegate are the only way to receive these important notifications.

应用程序代理和应用程序对象在一起配合工作能够保证应用正确的与iOS系统和另外的应用程之间的交互.具体来说,应用程序代理的方法给你一个处理系统发生重要改变的机会.比如,你可以使用应用程序代理的这些方法响应程序状态的变化,例如应用程序从前台切换到后台,响应传进来的通知.在许多情况下,应用程序代理的方法是接收系统重要通知的唯一方式.

Xcode provides an app delegate class for every new project, so you do not need to define one yourself initially. When your app launches, UIKit automatically creates an instance of the app delegate class provided by Xcode and uses it to execute the first bits of custom code in your app. All you have to do is take the class that Xcode provides and add your custom code.

Xcode为每一个项目提供了一个应用程序代理类,所以你不需要定义自己的初始化应用程序代理对象.当应用程序启动的时候,UIKit框架会自动创建由Xcode提供的这个应用程序代理的实例并且可以在对应的方法中写一些自定的代码当应用程序启动时.所有你要做的就是在Xcode提供的这个代理类对应的方法中编写自己的代码.

The app delegate is effectively the root object of your app. Like the UIApplication object itself, the app delegate is a singleton object and is always present at runtime. Although the UIApplication object does most of the underlying work to manage the app, you decide your app’s overall behavior by providing appropriate implementations of the app delegate’s methods. Although most methods of this protocol are optional, you should implement most or all of them.

应用程序代理实际上是应用程序的根对象,和UIApplicaiton对象一样,应用程序代理也是一个单例在应用程序的整个运行时都存在.虽然UIApplication对象管理了应用程序的底层工作,你也可以适当实现代理的方法来决定你应用程的总体行为.尽管这个协议的大多数方法是可选的,你应该实现大多数或者全部方法.

The app delegate performs several crucial roles:
It contains your app’s startup code.
It responds to key changes in the state of your app. Specifically, it responds to both temporary interruptions and to changes in the execution state of your app, such as when your app transitions from the foreground to the background.
It responds to notifications originating from outside the app, such as remote notifications (also known as push notifications), low-memory warnings, download completion notifications, and more.
It determines whether state preservation and restoration should occur and assists in the preservation and restoration process as needed.
It responds to events that target the app itself and are not specific to your app’s views or view controllers.
You can use it to store your app’s central data objects or any content that does not have an owning view controller.

你可能感兴趣的:(2.1UIApplicationDelegate官方说明)