ios重签名教程

iOS自动打包(重签名的方式)–用Mac客户端来实现

公司最近出了个需求,要求迅速给客户打一些马甲包,就是替换里面的plist和一些资源文件(icon和launchImage),于是找了很多资料,发现这一部分很多内容都已过期或者说讲的不全面,遂收集了一个全套的ipa重签名内容,分享给大家。代码是用swift写的,版本3.0

常量定义

struct PathDefine {
    static let UnzipPath = NSTemporaryDirectory().appending("unzip")
    static let TargetPath = "/Users/apple/Desktop"
    static let outputPath : String = "/Users/apple/Desktop/autoPackage"

}
struct OtherStringDefine {
    static let appid = "application-identifier"
    static let kTeamIdentifier = "com.apple.developer.team-identifier"
    static let kKeychainAccessGroups = "keychain-access-groups"
    static let codeSignature = "_CodeSignature"
    static let dbVersionKey = "dbVersion"
}

这些常量在以下内容中会用到

1解包

//解压之前先创建解压目录
 fileprivate func createWorkingPath() {
        let manager = FileManager.default
        if manager.fileExists(atPath: PathDefine.UnzipPath) == false {
            //不存在目录时创建一个
            do {
                try manager.createDirectory(atPath: PathDefine.UnzipPath, withIntermediateDirectories: true, attributes: nil)
            } catch {
                print(error.localizedDescription)
            }
        } else {
            // 存在目录时清空目录
            do {
                try manager.removeItem(atPath: PathDefine.UnzipPath)
            } catch  {
                print(error.localizedDescription)
            }

            //再创建一个
            do {
                try manager.createDirectory(atPath: PathDefine.UnzipPath, withIntermediateDirectories: true, attributes: nil)
            } catch {
                print(error.localizedDescription)
            }

        }
    }

    //这两个方法也是会多次被调用的,作用是监听task运行结果
    fileprivate func checkComplete(task : Process, complete : @escaping (Bool) -> Void) {
        Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(timerComplete(sender:)), userInfo: ["task" : task, "complete" : complete], repeats: true)
    }

    @objc private func timerComplete(sender : Timer) {
        let task : Process = (sender.userInfo as! Dictionary<String, Any>)["task"] as! Process
        let complete : (Bool) -> Void = (sender.userInfo as! Dictionary<String, Any>)["complete"] as! ((Bool) -> Void)
        if task.isRunning == false {
            sender.invalidate()
            if task.terminationStatus == 1 {
                complete(false)
            } else {
                complete(true)
            }
        }
    }

    //开始解包
     fileprivate func unzip(complete :@escaping (Bool) -> Void) {
        let task = Process.init()
        task.launchPath = "/usr/bin/unzip"
        //这个record.ipaInputPath是我模型中的变量,ipa母包的绝对路径 大家可以把ipa丢到终端里面,就可以看到了
        task.arguments = [ "-q", record.ipaInputPath, "-d", PathDefine.UnzipPath]
        let pi = Pipe.init()
        task.standardOutput = pi
        let file = pi.fileHandleForReading
        task.launch()
        let data = file.readDataToEndOfFile()
        print(String.init(data: data, encoding: .utf8) ?? "")
        self.checkComplete(task: task) { [unowned self] (result) in

            self.removeCodeSignature() //移除签名,内容在下面
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值