非8位图片在iOS9.3以下Crash

2019-01-17  本文已影响0人  转岗做JAVA

iOS9.3以下不兼容16位图片,使用16位图片会导致系统随机crash。

导出图片信息到Assets.json文件中

#!/bin/bash

ipaPath=$1
if [ '' != $ipaPath ]; then
    echo "IPA 路径为:$ipaPath"
else
    echo "IPA路径不能为空"
    exit
fi

unzip -oq $ipaPath -d ./ 
rm -r ./Symbols
cd ./Payload
for appFile in $(find . -name "Assets.car" ); do
    echo "Found app file: $appFile"
    cp -f $appFile ../Assets.car
done
cd ..
xcrun --sdk iphoneos assetutil --info ./Assets.car > ./Assets.json
rm -r ./Payload
rm ./Assets.car
# 这一步是copy到工程中,该工程用来取有问题的图片名。(不会用shell脚本去实现😄)
cp -f ./Assets.json ./ImageValidation/ImageValidation/Assets.json

取出非8位的图片名

override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let assetJsonPath = Bundle.main.path(forResource: "Assets", ofType: "json")
        let data = try! Data(contentsOf: URL(fileURLWithPath: assetJsonPath!, isDirectory: false))
        let models = try! JSON(data: data)
        let set = NSMutableSet()
        for (_, subJson) in models {
            let bit = subJson["BitsPerComponent"].intValue
            if bit != 0 && bit != 8 {
                let name = subJson["Name"].string!.replacingOccurrences(of: ".png", with: "")
                let renditionName = subJson["RenditionName"].string!.replacingOccurrences(of: ".png", with: "")
                set.add(name)
                set.add(renditionName)
            }
        }
        let myArray: Array<String> = Array(set) as! Array<String>
        // 格式化打印出来的值,作为下一步脚本中的输入参数
        print("\"\(myArray.joined(separator:" "))\"")
    }

将有问题的图片统一拷贝到images文件夹中

#!/bin/bash
array_name=$1
empty=""

if [ $array_name -eq $empty ]; then 
    echo "查找文件不能为空"
    exit
fi
mkdir -p ./images/
rm -f ./images/*

for fileName in ${array_name[@]}; do
    echo "查找文件:$fileName"
    for findFile in $(find 你App的工程路径 -name "$fileName.*"); do
        echo "拷贝文件:$findFile"
        cp -f $findFile ./images/
    done
done

处理非8位的图片

这个网站可以便捷处理图片为8位:https://tinypng.com
上面也有Api可供使用:https://tinypng.com/developers

上一篇下一篇

猜你喜欢

热点阅读