码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 小技巧总结

时间:2015-04-29 19:31:04      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

 

1.获取准确的app启动所需时间

应用启动时间长短对用户第一次体验至关重要,同时系统对应用的启动、恢复等状态的运行时间也有严格要求,在应用超时的情况下系统会直接关闭应用。
以下是几个常见场景下系统对App运行时间的要求:

Launch 20秒
Resume 10秒
Suspend 10秒
Quit 6秒
Background Task 10分钟

 

1)在点main.m文件中加入

CFAbsoluteTime StartTime;//开始时间
int main(int argc, char * argv[]) {
    @autoreleasepool {
         StartTime=CFAbsoluteTimeGetCurrent();//开始时间
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

 

2)AppDelegate.m文件中加入

@interface AppDelegate ()

/**
 *  声明startTime,用以在本类中调用main.m中的startTime全局变量。
 */
extern CFAbsoluteTime StartTime;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];
    
     NSLog(@"程序启动耗时%f秒!",CFAbsoluteTimeGetCurrent()-StartTime);//时间差

    return YES;
}

 

 

 
 
 

iOS 小技巧总结

标签:

原文地址:http://www.cnblogs.com/sixindev/p/4466482.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!