The meaning of the functions of appdelegate in iOS

Source: Internet
Author: User


When you first contact with iOS, every time you build a project, the system will automatically generate a Appdelegate class, which a variety of functions, for beginners of me, is really a little confused, do not know how to use, Today we will talk about some usages and meanings of appdelegate.

Look at the meaning of some functions in the APPDELEGATE.M file.


//
Appdelegate.m
//
//
Created by Kenshin Cui on 14-2-23.
Copyright (c) 2014 Kenshin Cui. All rights reserved.
//

#import "AppDelegate.h"

@implementation Appdelegate

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions
{
return YES;
}

-(void) Applicationwillresignactive: (uiapplication *) application
{
Sent when the application are about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or the US Er quits the application and it begins the transition to the background state.
Use the To pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should to pause the game.
}

-(void) Applicationdidenterbackground: (uiapplication *) application
{
Use the to release shared resources, save user data, invalidate timers, and store enough application state info Rmation to restore your application to the it is terminated later.
If your application supports background execution, this is called instead of Applicationwillterminate:when the User quits.
}

-(void) Applicationwillenterforeground: (uiapplication *) application
{
Called as part of the transition from the background to the inactive state; Here you can undo many of the changes made on entering the background.
}

-(void) Applicationdidbecomeactive: (uiapplication *) application
{
Restart any tasks this were paused (or not yet started) while the application is inactive. If the application is previously in the background, optionally refresh the user interface.
}

-(void) Applicationwillterminate: (uiapplication *) application
{
Called when the application was about to terminate. Save data if appropriate. Also applicationdidenterbackground:.
}

@end
In fact, this class defines how each event in the application lifecycle is executed:

– (BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions; After the program is started, it will not be executed until after the first program is started;

– (void) Applicationwillresignactive: (uiapplication *) application, the program will be activated when the program activates the user to operate;

– (void) Applicationdidenterbackground: (uiapplication *) application, the program into the background after the execution, attention to enter the background will lose focus before entering the background;

– (void) Applicationwillenterforeground: (uiapplication *) application; The program will be executed when it enters the foreground;

– (void) Applicationdidbecomeactive: (uiapplication *) application, after the program is activated, note that when the program is activated, it will first enter the foreground and then be activated;

– (void) Applicationwillterminate: (uiapplication *) application, the program executes at termination, including normal termination or abnormal termination, For example, an application that uses too much memory in a daemon unexpectedly terminates the call to this method;

The meaning of all functions here is also clear, I am accustomed to some of the entire application of some properties or functions, directly written in-(BOOL) Application: (UIApplication *) application Didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions, this function inside, so I also saved a lot of time, the use of other functions, we can open to the imagination.

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.