移动应用的性能

2018-04-02  本文已影响0人  夜雨聲煩_
内存

内存泄漏,会导致应用随时间进行而内存消耗不断增长。应用最后会因为内存不足异常崩溃。

电量

电量的消耗主要与计算 CPU 周期和高效的使用硬件有关。

初始化时间

初始化阶段应该做的一些事:

设置工程和代码

使用 CocoaPods ,该者为 Objective-C 和 Swift 工程的依赖管理器。使用其与 Xcode 命令行工具相集成,用于构建和发布。
使用方法:
安装 CocoPods
建立 SingleViewApp
进入响应路径使用命令行 touch Podfile
open Podfile 并加入:

platform :ios, '7.0'
target '项目名' do
pod 'CocoaLumberjack' , '~> 2.0'
end

顺便补充下关于版本符号说明:

Besides no version, or a specific one, it is also possible touse logical operators:
'> 0.1'    Any version higher than 0.1 
'>= 0.1'   Version 0.1 and any higher version
'< 0.1'    Any version lower than 0.1
'<= 0.1'   Version 0.1 and any lower version  

In addition to the logic operators CocoaPods has an optimisicoperator ~>:
'~> 0.1.2' Version 0.1.2 and the versions up to 0.2, not including 0.2 and higher
'~> 0.1' Version 0.1 and the versions up to 1.0, not including 1.0 and higher 
'~> 0' Version 0 and higher, this is basically the same as not having it.  

重新启动并运行workspace即可

埋点和崩溃报告

使用 Flurry 设置

日志

通过 CocoaPods 引入 CocoaLumberjack 。

//为 CocoaLumberjack 配置 Podfile
pod 'CocoaLumberjack'  , '~> 2.0'

使用:

#import <Foundation/Foundation.h>
#import "CocoaLumberjack.h"

#if DEBUG
static const DDLogLevel ddLogLevel = DDLogLevelVerbose;
#else
static const DDLogLevel ddLogLevel = DDLogLevelWarning;
#endif
@interface CPLog : NSObject

@end
#import "CPLog.h"

@implementation CPLog

+ (void)load
{
    [DDLog addLogger:[DDASLLogger sharedInstance]];
    DDFileLogger *fileLogger = [[DDFileLogger alloc] init];
    fileLogger.rollingFrequency = 60 * 60 * 24;
    fileLogger.logFileManager.maximumNumberOfLogFiles = 7;
    [DDLog addLogger:fileLogger];
}

@end

关于 DEBUG 可以在 Build Setting 中修改 DEBUG 的值,也可以在 Edit Scheme 修改 Run 的模式。

上一篇 下一篇

猜你喜欢

热点阅读