移动应用的性能

内存

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

电量

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

初始化时间

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

  • 检查应用是否为初次启动
  • 检查用户是否已经登录
  • 如果用户已经登录,尽可能载入之前状态
  • 链接服务器以拉去最新的变更
  • 检查应用是否由猫狗深层链接唤起。如果是,还需要载入申城链接相应的UI和状态
  • 检查是否存在应用上次启动时挂起的任务,需要时恢复它们
  • 初始化后续需要使用的对象和线程池
  • 初始化依赖项(如对象关系映射、崩溃报告系统和缓存)
设置工程和代码

使用 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 的模式。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容