IOS开发UI之UIApplicationDelegate协议介绍

随声附和 提交于 2020-02-29 14:29:52

#import "AppDelegate.h"


@interface AppDelegate ()


@end


@implementation AppDelegate


//====================以下方法都是UIApplicationDelegate协议方法========


//这个方法是应用程序已经启动成功后调用

//这个方法可以看成IOS应用程序真正的入口

//参数一:委托(当前这个应用程序对象)

//参数二:加载选项

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

    //在这个方法里面实现所有功能(包括数据下载,数据解析和数据显示)

    NSLog(@"应用程序启动成功!!!");

    //在这儿实现应用程序的功能.

    

    

    // Override point for customization after application launch.

    return YES;

}



//Resign放弃

//应用程序将要编程非活跃状态的时候会调用这个方法

//home键或者来电

//cmd+shift+h :模拟按home

- (void)applicationWillResignActive:(UIApplication *)application {

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

  

    NSLog(@"变成非活跃状态!");


}


//应用程序进入后台的时候调用这个方法:home

- (void)applicationDidEnterBackground:(UIApplication *)application {

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

 //在这个函数中一般关闭定时器,暂停游戏,暂停视频播放等

    NSLog(@"home键进入后台~");



}

//应用程序将要进入前台调用这个方法:显示在界面上

- (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.

   

    //开启定时器,游戏继续和视频继续播放等;

    NSLog(@"将要进入前台");


}


//应用程序已经变成活跃状态会调用这个方法(应用程序显示在界面的那一刻)

- (void)applicationDidBecomeActive:(UIApplication *)application {

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

    //

    NSLog(@"已经变成活跃状态~~~");



}


//应用程序将要终止的时候调用这个方法:程序不再运行;

- (void)applicationWillTerminate:(UIApplication *)application {

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

    //不让应用程序在后台运行

    //设置info.plist文件添加Application does not run in..置为YES

    NSLog(@"应用程序将要终止!!");


}


@end


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!