IOS programming basics-event-driven and program status

Source: Internet
Author: User
. Event-drivenIOS programming is event-driven. All we need to do is write code to respond to the corresponding event. Each time a user operates an application, the device generates an event. For example, when a user clicks a button, the device generates a corresponding "Touch" event and sends it to the application. Events not only come from direct user interaction, such as incoming calls, insufficient power, and file download completion, but also generate events. In fact, everything that happens on IOS devices will eventually generate one or more events. When an event is generated, the operating system checks your program to see if a method in a class should be notified. The key to iOS programming is to know what events are there? And how to set our methods so that when these events occur, the corresponding methods can be called? Understanding the lifecycle of a program is critical. A simple display of the event stream from startup to completion of a program:

At a critical point in the life cycle of a program, messages are sent to objects in the application so that these objects can know what is going on. When you press the Home key, the Program on IOS does not actually end, but is suspended in the background.

. Program Status
The core of our program is the main function. When we create a project based on the corresponding template, Xcode will automatically create this function for me. Generally, we do not need to make any changes. So what is its role?
It serves as the entry to the application. After entering this entry, it transfers control to a class in the UIkit framework.

Each iOS application must have a class that implements the UIApplicationDelegate protocol. This class is the application proxy object, which monitors the high-level behavior of the application. The application proxy object must implement some key methods in the UIApplicationDelegate protocol, which are used to handle some key events.

In object-oriented methods, a proxy is an object that implements some methods. These methods are called by another object as needed.
The status of all iOS programs is as follows:

Not running Application not started currently
Not activated

The application is running, but does not receive any events. When an application is about to switch from one status to another, it is in the inactive status and in this status.

Is very short. The application remains inactive for a period of time only when the system prompts the user to respond to certain events, such as incoming calls and new information.

Activate The program is running and receives the event
The day after tomorrow The application runs the day after tomorrow. Generally, it does not directly interact with users.
Pending No code is executed and is in the waiting status.

 

 

 

 

 

 

At startup, a program is not in the active or background status.

The method calling sequence of the application proxy protocol is as follows:
Didfinishlaunchingwitexceptions
ApplicationDidBecomeActive
ApplicationDidEnterBackground
Xcode usually provides the default implementation of these methods.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.