• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iOS swift 获取 app 打包时间 版本 手机系统

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

因为提交给测试的测试包太多 出问题的包可能会混 

所以加了个打包时间 和其他的一些app 和手机信息  方便测试在提BUG的时候带上

1. 在 Xcode 工程对应 Target 的 build Phases 中新增 run Scrpit Phase


2 创建 buildTime.pilst


3 创建shell脚本

#!/bin/sh

set -e

# plist 文件地址

PLIST_PATH="./iTour/BuildTime.plist"

BUILD_TIME_KEY=":BuildTime"

BUILD_TIME_VALUE="$(date +%Y年%m月%d日%H时%M分%S秒)"


if [ -r "${PLIST_PATH}" ]; then

    /usr/libexec/PlistBuddy -c "Set ${BUILD_TIME_KEY} ${BUILD_TIME_VALUE}" "${PLIST_PATH}"

else

    /usr/libexec/PlistBuddy -c "Add ${BUILD_TIME_KEY} string ${BUILD_TIME_VALUE}" "${PLIST_PATH}"    

fi


4 取时间

单取个时间 挺麻烦 我就都贴上了

struct AppInfo {

    static let AppName = ""

    static let SystemType = "ios"

    static let ChannelSource = "App store"

    static let VersionName = String(describing: Bundle.main.infoDictionary!["CFBundleShortVersionString"]!)

    static let VersionCode = String(describing: Bundle.main.infoDictionary!["CFBundleVersion"]!)

    static let BundleIdentifier = Bundle.main.bundleIdentifier!

    static let KmilesBuildTime: String? = {

        if let path = Bundle.main.path(forResource: "BuildTime", ofType: "plist"),

            let dic = NSDictionary(contentsOfFile: path) as? [String: AnyObject],

            let result = dic["BuildTime"] as? String {

            return result

        }

        return nil

    }()

    static let IPhoneOS: String = {

        return UIDevice.current.systemVersion

    }()

    static let IPhoneType: String = {

        var systemInfo = utsname()

        uname(&systemInfo)

        let machineMirror = Mirror(reflecting: systemInfo.machine)

        let identifier = machineMirror.children.reduce("") { identifier, element in

            guard let value = element.value as? Int8, value != 0 else { return identifier }

            return identifier + String(UnicodeScalar(UInt8(value)))

        }

        switch identifier {

        case "iPod5,1":                                 return "iPod Touch 5"

        case "iPod7,1":                                 return "iPod Touch 6"

        case "iPhone3,1", "iPhone3,2", "iPhone3,3":     return "iPhone 4"

        case "iPhone4,1":                               return "iPhone 4s"

        case "iPhone5,1", "iPhone5,2":                  return "iPhone 5"

        case "iPhone5,3", "iPhone5,4":                  return "iPhone 5c"

        case "iPhone6,1", "iPhone6,2":                  return "iPhone 5s"

        case "iPhone7,2":                               return "iPhone 6"

        case "iPhone7,1":                               return "iPhone 6 Plus"

        case "iPhone8,1":                               return "iPhone 6s"

        case "iPhone8,2":                               return "iPhone 6s Plus"

        case "iPhone9,1":                               return "iPhone 7"

        case "iPhone9,2":                               return "iPhone 7 Plus"

        case "iPhone10,1","iPhone10,4":                 return "iPhone 8"

        case "iPhone10,2","iPhone10,5":                 return "iPhone 8 Plus"

        case "iPhone10,3","iPhone10,6":                 return "iPhone X"

        case "iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4":return "iPad 2"

        case "iPad3,1", "iPad3,2", "iPad3,3":           return "iPad 3"

        case "iPad3,4", "iPad3,5", "iPad3,6":           return "iPad 4"

        case "iPad4,1", "iPad4,2", "iPad4,3":           return "iPad Air"

        case "iPad5,3", "iPad5,4":                      return "iPad Air 2"

        case "iPad2,5", "iPad2,6", "iPad2,7":           return "iPad Mini"

        case "iPad4,4", "iPad4,5", "iPad4,6":           return "iPad Mini 2"

        case "iPad4,7", "iPad4,8", "iPad4,9":           return "iPad Mini 3"

        case "iPad5,1", "iPad5,2":                      return "iPad Mini 4"

        case "iPad6,7", "iPad6,8":                      return "iPad Pro"

        case "AppleTV5,3":                              return "Apple TV"

        case "i386", "x86_64":                          return "Simulator"

        default:                                        return "Unknown"

        }

    }()

}


遮住的只是我的app名字 没有影响

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Swift编程规范发布时间:2022-07-13
下一篇:
[Swift]LeetCode882.细分图中的可到达结点|ReachableNodesInSubdividedGraph ...发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap