您的位置:首页 > 移动开发

IOS中AppDelegate类中的方法触发时机-----自定义AppDelegate的写法

2015-08-27 21:43 411 查看
@implementation AppDelegate

//当应用程序加载时触发,创建window窗口对象,让对象的window成为程序的主窗口,并且可视.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
//__FUNCTION__方法名__LINE__所在的行数
NSLog(@"%s,%d",__FUNCTION__,__LINE__);

self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
//应用程序将要取消活跃状态是触发'
//使用该方法暂停掉正在执行的任务,让定时器失效,暂停游戏.
- (void)applicationWillResignActive:(UIApplication *)application {
NSLog(@"%s,%d",__FUNCTION__,__LINE__);
// 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.
}
//当应用程序进入后台时触发
//释放共享资源,保存用户数据,让timer失效,保存当前程序退出时会替换applicationWillTerminate
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSLog(@"%s,%d",__FUNCTION__,__LINE__);
// 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.
}
//当应用程序将要进入前台时触发
//继续进入后台时正在运行的任务,游戏继续进行
- (void)applicationWillEnterForeground:(UIApplication *)application {
NSLog(@"%s,%d",__FUNCTION__,__LINE__);
// 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 {
NSLog(@"%s,%d",__FUNCTION__,__LINE__);
// 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.
}

- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
-(void)dealloc
{
[_window release];
[super dealloc];
}
@end


重写AppDelegate

//LODelegate,注意继承

// UIResponder<UIApplicationDelegate>


@interface LODelegatre : UIResponder<UIApplicationDelegate>
@property (retain, nonatomic) UIWindow *window;
@end


#import "LODelegatre.h"

@implementation LODelegatre
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];;
self.window.backgroundColor = [UIColor yellowColor];
[self.window makeKeyAndVisible];
return YES;
}
- (void)dealloc
{
[_window release];
[super dealloc];
}
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: