V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
yellowV2ex
V2EX  ›  iDev

你们最近有没有遇到一个问题, App 的开启时间非常长,就算是一个空项目,用了 swift, use_frameworks!, cocoapods

  •  
  •   yellowV2ex · 2015-09-23 10:07:12 +08:00 · 8237 次点击
    这是一个创建于 3131 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我之前偶尔会遇到启动( launch )时间过久,点了 App ,出现 launch image ,然后就卡住,因为 iOS9 出来了,应用启动时间不能超过 20 秒,所以会导致自动退出。

    我开始以为是第一屏的内容太多,在加载导致的,但当我建了一个空 project ,再试的时候,我完全觉得这确实是一个问题。

    情况跟 stackoverflow 上这个问题一模一样, http://stackoverflow.com/questions/31080284/ ,但我的载入时间比他还久。

    io 在模拟器和 debug 模式下,完全没有问题,但 release 的版本后在真机测试,开启时间非常的久, Console 里只有这一句一直重复:

    Sep 22 09:58:05 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:07 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:09 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:11 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:12 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:14 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:16 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:19 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:21 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:23 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:25 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:27 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:29 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:31 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:33 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:35 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:36 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:38 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:40 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    Sep 22 09:58:42 yellows-iPhone installd[4677] <Error>:  SecTrustEvaluate  [leaf IssuerCommonName SubjectCommonName]
    

    我在用这个方法 http://stackoverflow.com/a/31573908/1297795 再调试,发觉 93%的时间花在了 load images 上,但我是个空项目,完全没有内容,那么 images 只能在 pods 里了,我找了一圈,就算是 pods 里所有的图片加起来,也就几十张, iOS 不可能载入几张图片就花了 20 秒,并且只是 release ,真机有问题。

    我重新做了 CertificateSigningRequest.certSigningRequest 和描述文件,因为我搜到有些问题说重新做一个证书就可以,但我试过还是不行,我又尝试新建一个 app id ,再走一遍,也是不行。

    我重新整理了一下流程,用 cocoapods 的人不少,我觉得这确实是一个问题,不少人会遇到。

    环境 Xcode 7 + iOS9 ,用 cocoapods ,并且 pod 里有 swift 的项目,并且用 use_frameworks!

    1. 新建一个空项目
    2. 把结尾的内容存到podfile文件,存在项目目录
    3. 在项目目录的终端运行 pod install
    4. 打开 workspace 文件
    5. Scheme 里把 build configuration 设为 release
    6. 然后选择你的 iPhone , run

    podfile:

    source 'https://github.com/CocoaPods/Specs.git'
    platform :ios, '8.0'
    use_frameworks!
    
    pod 'AFNetworking', '~> 1.3.4'
    pod 'YTKKeyValueStore'
    pod 'JGProgressHUD'
    pod 'ODRefreshControl'
    pod 'WCAlertView'
    pod 'Reachability'
    pod 'InfinitePagingView'
    pod 'NJKWebViewProgress'
    pod 'M13BadgeView'
    pod 'Masonry'
    pod 'MJRefresh' , '~> 2.4.7'
    pod 'Colours' , '~> 5.6.2'
    pod 'ViewUtils'
    pod "SDVersion"
    pod 'NSDate+TimeAgo'
    pod 'TPKeyboardAvoiding'
    pod 'AutoSlideScrollView'
    pod 'ZipArchive'
    pod 'imglyKit' , '~> 2.4'
    

    你会发现,启动时间超过了十秒才进去,如果开启 iOS9 的省电模式,会超过 20 秒,我试过将 podfile 删掉一些,虽然启动时间有变短一点点,但还是要非常久。
    当 app 在你手机上了,你尝试将他完全退出,双击 home ,关掉,然后运行一些其他 app ,再回到手机开启 app ,时间跟开始一样。

    stackoverflow 那位题主有份代码可直接供你测试, https://github.com/hlung/TrySlowAppSwift ,一定要在真机,模拟器没有问题。

    脱水:

    相关问题: http://stackoverflow.com/questions/31080284/
    相关代码: https://github.com/hlung/TrySlowAppSwift
    错误 log :SecTrustEvaluate [leaf IssuerCommonName SubjectCommonName]
    关键字: cocoapods, use_frameworks!, swift, launch, SecTrustEvaluate

    8 条回复    2015-09-24 16:23:53 +08:00
    gulullu
        1
    gulullu  
       2015-09-23 10:18:41 +08:00
    为毛的我模拟器也是这样,卡在启动页面好久,还以为是启动图太大呢,结果缩小后还是那样, oc 代码,用了 Cocoapods
    yellowV2ex
        2
    yellowV2ex  
    OP
       2015-09-23 10:21:12 +08:00
    @gulullu 是,我得模拟器还好,但真机真是慢的离谱,我以为 Cocoapods 的 pre-release 版本问题,用 38.2 也不行 39 beta4 还是一样,我有点怀疑是 xocde7 和 cocoapods 不兼容的之类的问题,我打算一会儿用 xcode6 试试
    xjbeta
        3
    xjbeta  
       2015-09-23 10:44:16 +08:00
    前两天无故报错 新建项目同样错误 cleanmymac 清理了下就好。。。
    gulullu
        4
    gulullu  
       2015-09-23 11:15:13 +08:00
    @yellowV2eXcode 6 是正常的貌似
    onevcat
        5
    onevcat  
       2015-09-23 11:25:28 +08:00   ❤️ 1
    1. 这里的 images 指的应该是 dynamic framework 本身,而不是图片。比如加载动态库时找不到的时候报错是这样的:
    dyld: Library not loaded: XXXX.framework
    Reason: image not found

    问题在于加载库的速度慢。

    2. 实测了一下,似乎第一次有点慢,后来的几次启动看起来没什么问题 https://infinit.io/_/Aen5R2b

    3. 不过有个例外,就是如果刚连上 lighting cable 的时候, iTunes 和 Photo 会打开读取 iPhone 内容,这个时候打开 app 的话会比较慢。但是因为同时有不少 I/O 在做,也可以理解。在等待 iTunes 和 Photo 完成工作后,启动速度和上面的视频一样。
    yellowV2ex
        6
    yellowV2ex  
    OP
       2015-09-23 11:37:55 +08:00
    @onevcat 非常感谢,但我文章里那几个 pod ,本来第一次 load 久一点也没有关系,但 iOS9 出来之后,他会自动闪退,因为时间超过了 20 秒, Crash log 会有这一条:



    Exception Type: 00000020
    Exception Codes: 0x000000008badf00d
    Exception Note: SIMULATED (this is NOT a crash)
    Highlighted by Thread: 0

    Application Specific Information:
    com.eye4gift.Eye4giftCard failed to launch after 20.00s (launchIntent: foreground-interactive)

    Elapsed total CPU time (seconds): 25.070 (user 25.070, system 0.000), 63% CPU
    Elapsed application CPU time (seconds): 0.000, 0% CPU

    Filtered syslog:
    None found



    看上去好像是 iOS 9 设定了应用启动时间不可以超过 20 秒。

    我试过双击 home 退出之后再打开确实是快了,但我后来发现其实是没有真正的清除掉,当我删掉再重新下载安装后(企业证书),第一次打开,他还是会退,我的 iphone6 和 5C 都有这个问题,当他闪退再打开,他会正常进去了。

    确实是 framework 的载入花了时间,看来如果要 oc 和 swift 混合的项目,只能尽量减少在 podfile 里的项目数了。


    如果各位有空的话,麻烦帮忙测试一下这个 app : http://fir.im/i4g ,非常感谢。
    我的 iPhone6 实测,第一次打开会 20 秒闪退,第二次再打开才可以。
    yellowV2ex
        7
    yellowV2ex  
    OP
       2015-09-23 11:51:21 +08:00
    上面说的这个 app http://fir.im/i4g ,按照 @onevcat 的操作方式,看上去也没有什么问题,但就是第一次打开的时间非常非常久,难道 iOS 会把一些 framework 缓存起来?
    上周还是 iOS8 的时候,并没有发现这个问题。
    yellowV2ex
        8
    yellowV2ex  
    OP
       2015-09-24 16:23:53 +08:00
    大概原因找到了,我的是 objc 项目,用了一个 swift 的库,混编出来之后,在 app 的 frameworks 目录里,有一堆 swift 相关的 dylib ,而载入时间就花在了这些东西上。
    暂时无法解决,我只能换掉一个 swfit 写的库,现在是纯 objc 项目
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   931 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 22:13 · PVG 06:13 · LAX 15:13 · JFK 18:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.