背景
最近公司項目集成了Bugly,發(fā)現(xiàn)線上版本奔潰概率達到了2%,怪不得AppStore評論里有人在【罵娘】瓢省。主要問題是有一個Signal 10 was raised. SIGBUS (_mh_execute_header + 795252)的bug,但在奔潰堆棧中查不到有用信息。從統(tǒng)計數(shù)據(jù)中發(fā)現(xiàn)决帖,奔潰大多出現(xiàn)在iOS9.0-iOS9.3之間的版本蚓胸。
找手機一波三折
發(fā)現(xiàn)崩潰大多出現(xiàn)在iOS9.0-9.3挣饥,iPhone6、6 Plus赢织、6s亮靴、6s Plus手機上,因為測試人員沒有iOS9.3以下版本的手機于置,所以就暫時擱置沒解決茧吊。
第二天早晨一看奔潰率增加,已經(jīng)到了非解決不可的地步八毯。于是我們先在公司群里懸賞吆喝誰有iOS9.3以下的手機搓侄,公司400多人沒一個??。
實在沒辦法只能借助網(wǎng)友的力量了话速,先后經(jīng)過了發(fā)微博讶踪、技術(shù)交流群里尋找?guī)椭罱K找到了2個有該系統(tǒng)手機的網(wǎng)友泊交,然后讓他們幫忙下載測試乳讥,果然必崩。本來想如果他們在北京廓俭,立刻過去找他們現(xiàn)場測試云石,請客吃頓飯就解決了,可他們都不在北京研乒,嗚呼哀哉汹忠。
有一個同事提議可以上網(wǎng)租一個測試機,我們就找到了“租測云”租用了一臺iOS9.1版本的測試機,”租測云“還挺給力宽菜,中午就把手機送來了谣膳。
柳暗花明又一村
拿到測試機后,先從AppStore下載線上版本铅乡,運行一會就隨機在任何頁面崩潰了继谚。
我先在Xcode上下載iOS9.2的模擬器運行正常。
接著用真機測試也不會崩潰隆判。
然后各種測試接連經(jīng)歷了嘗試-懷疑-不解-納悶-困惑-發(fā)狂-迷茫等心理路程都沒找到原因犬庇,也沒遇到崩潰情況。
后來想到既然只有從AppStore下載才出現(xiàn)問題侨嘀,懷疑是打包出了問題臭挽,然后就重新打包上傳到iTunes Connection,用TestFlight功能進行內(nèi)測咬腕。果然從TestFlight下的版本崩潰了欢峰。然后就上網(wǎng)各種查找Xcode8打包iOS9線上奔潰問題的資料,最終鎖定到了P3資源文件的問題上涨共。
Stackoverflow有一個相同的問題我按照他的查找方式纽帖,果然發(fā)現(xiàn)我們項目中有一張P3格式資源圖片,這張圖片只有在測試環(huán)境下才會用到举反,線上怎么會崩潰呢0弥薄?抱著試試的態(tài)度我買了一個療程(刪除了這張圖片)火鼻,然后重新打包上傳TestFlight下載一切運行正常室囊,看來真是一張圖片造成的慘案。
解決方式
檢查自己項目中是否包含16-bit或者P3格式圖片的方式如下:
1. Create an Inspectable .ipa file. In the Xcode Organizer (Xcode->Window->Organizer), select an archive to inspect, click “Export...", and choose "Export for Enterprise or Ad-Hoc Deployment". This will create a local copy of the .ipa file for your app.2. Locate that .ipa file and change its the extension to .zip.3. Expand the .zip file. This will produce a Payload folder containing your .app bundle.4. Open a terminal and change the working directory to the top level of your .app bundlecd path/to/Payload/your.app 5. Use the find tool to locate Assets.car files in your .app bundle as shown below:find . -name 'Assets.car' 6. Use the assetutil tool to find any 16-bit or P3 assets, in each Assets.car your application has as shown below. :sudo xcrun --sdk iphoneos assetutil --info /path/to/a/Assets.car > /tmp/Assets.json 7. Examine the resulting /tmp/Assets.json and look for any contents containing “DisplayGamut": “P3” and its associated “Name". This will be the name of your imageset containing one or more 16-bit or P3 assets. 8. Replace those assets with 8-bit / sRGB assets, then rebuild your app.
###解決方式:
1魁索、方法一(單個處理問題圖片):
指派它的描述文件為sRGB IEC61966-2.1融撞,應(yīng)用->保存。
再次編譯運行我們的APP粗蔚,發(fā)現(xiàn)問題解決了尝偎!
2.方法二(暴力處理所有圖片):
這里我們使用bash script直接處理所有圖片為正確格式,這樣我們就不用去定位是哪個圖片的問題了鹏控,或許更方便一些致扯。
```
#!/bin/bashDIRECTORY=$1echo"------------------------------"echo"Passed Resources with xcassets folder argument is <$DIRECTORY>"echo"------------------------------"echo"Processing asset:"XSAASSETSD="$(find "$DIRECTORY" -name '*.xcassets')"forxcassetin$XSAASSETSDdoecho"---$xcasset"IMAGESETS="$(find "$xcasset" -name '*.imageset')"forimagesetin$IMAGESETSdoecho"------$imageset"FILES="$(find "$imageset" -name '*.png')"forfilein$FILESdoecho"---------$file"sips -m"/System/Library/Colorsync/Profiles/sRGB Profile.icc"$file--out$filedonedonedoneecho"------------------------------"echo"script successfully finished"echo"------------------------------"
```