美文网首页
xcode一次运行多个模拟器

xcode一次运行多个模拟器

作者: mrkison | 来源:发表于2022-06-24 07:52 被阅读0次

现在的Mac配上M1芯片后性能是强大许多,不知M2什么样,在电脑上运行4、5个模拟器调试都不卡,但是每次改完代码运行4、5个模拟器还是觉得手有点累(虽然也不是那么累),本着能少动手就少动手的理念,就想怎么能减少操作。

1、运行模拟器使用xcrun simctl命令
1.1、xcrun simctl list能获取到所有模拟器设备的uuid,把你需要的模拟器uuid记下来后面使用。
1.2、xcrun simctl install 模拟器uuid .app路径这是安装.app到模拟器,.app的路径在看下图,当你运行了app后就会生成,托入终端就能得到路径了

image.png
1.3、xcrun simctl launch 模拟器uuid .app的BundleID启动模拟器.app,BundleID看下图
image.png
运行这几个命令就能安装并打开一个.app了。既然一个会了,多个就不是问题了,只需要用脚本就好了。

2、运行多个模拟器的shell
问题:一般我们运行都是需要调试其中一个模拟器,但是我没找到什么方法能获取到当前xcode所运行的模拟器(希望有知道的朋友能分享下),所以只能在didFinishLaunchingWithOptions后获取到设备型号,写入到桌面文件记录,然后shell再到里面读取;

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        //这是将设备型号写入文件,路径可以自己随意。
        #if DEBUG
            let desk = NSSearchPathForDirectoriesInDomains(.desktopDirectory, .userDomainMask, true)
            let tempFilePath = desk.first!
            if let rang = tempFilePath.range(of: "/Library") {
                let filePath = String(tempFilePath[...rang.lowerBound]) + "Documents/创建的需要写入设备型号的文件"
                if FileManager.default.fileExists(atPath: filePath),
                   let nameData = UIDevice.current.name.data(using: .utf8)
                {
                    FileManager.default.createFile(atPath: filePath, contents: nameData)
                }
            }
        #endif
        return true
    }

最后就是shell代码

#!/bin/bash
#读取当前运行的模拟器
line=$(cat ~/Documents/创建的需要写入设备型号的文件)
#判断如果正在运行的模拟器不是`iPhone 12 mini``就安装并运行.app
if [ "$line" != "iPhone 12 mini" ]; then
xcrun simctl install 模拟器uuid .app路径
xcrun simctl launch 模拟器uuid .app的BundleID
fi

if [ "$line" != "iPhone 12" ]; then
xcrun simctl install 模拟器uuid .app路径
xcrun simctl launch 模拟器uuid .app的BundleID
fi
下面可以继续写其他的设备

操作步骤:先用xcode运行一台你需要链接调试的模拟器,其他的在终端执行这一段shell就能安装并运行了。

鼠标党继续

我们鼠标党不想执行终端,我们就能使用Mac自带的自动操作。


image.png

自动操作 -> 新建文稿 -> 工作流程 -> 实用工具 -> 运行shell脚本


image.png

到此完结!!!

相关文章

网友评论

      本文标题:xcode一次运行多个模拟器

      本文链接:https://www.haomeiwen.com/subject/pxrbvrtx.html