简体   繁体   English

如何动态获取IOS模拟器设备的UID,然后安装到该设备中

[英]How to dynamically get the UID of the IOS simulator device and then install in that device

How to dynamically get the UID of the IOS simulator device and then install it in that device.如何动态获取IOS模拟器设备的UID,然后安装到该设备中。 I currently have this BASH script which does the job, however, when I run that code on a different machine, I need to manually change the ID every time which makes the automation difficult.我目前有这个 BASH 脚本可以完成这项工作,但是,当我在另一台机器上运行该代码时,我每次都需要手动更改 ID,这使得自动化变得困难。 How can I get the UID just by defining the device type such as IPHONE.8 get the ID and use that instead如何仅通过定义 IPHONE 等设备类型来获取 UID。8 获取 ID 并改用它

#!/bin/bash
export PATH=/usr/local/bin:$PATH

# define variables
DESTINATION="platform=iOS Simulator,name=iPhone 8,OS=13.4.1"
IPHONE_VERSION_ONE="iPhone-7"
APPDIR="$HOME/Library/Developer/Xcode/DerivedData/"
APP_NAME="In-House-iphonesimulator/test.app"
PHONE_ID_ONE="AB877AA-2178-4C29-BF4F-556456C"


xcrun simctl install $PHONE_ID_ONE $APP_LOCATION || { echo 'Unable to install App to Iphone7' ; exit 1; }

Also i put the below answer in the variable, however how to put quotes when store it in a variable?我也把下面的答案放在变量中,但是如何在将它存储在变量中时加上引号?

PHONE_ID="instruments -s devices | grep -m 1 "iPhone 8" | awk -F'[][]' '{print $2}'"

instruments -s devices | grep "iPhone 8" | awk -F'[][]' '{print $2}'

Here what this command is doing:这是此命令的作用:

  1. Listing all of your iOS devices列出您所有的 iOS 设备
  2. Searching for iPhone 8 over the results在结果中搜索iPhone 8
  3. Splitting the string by square brackets and printing the second token.用方括号拆分字符串并打印第二个标记。

So you as a result should get UDID only: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX因此,您应该只获得 UDID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

If you have more than one iPhone 8 simulator in your system, you can limit the output by adding -m 1 key to the grep command:如果你的系统中有多个 iPhone 8 模拟器,你可以通过在 grep 命令中添加-m 1键来限制 output:

instruments -s devices | grep -m 1 "iPhone 8" | awk -F'[][]' '{print $2}'

Just assign the result of this command to your PHONE_ID_ONE variable using $() :只需使用$()将此命令的结果分配给您的PHONE_ID_ONE变量:

PHONE_ID="$(instruments -s devices | grep -m 1 'iPhone 8' | awk -F'[][]' '{print $2}')"

Hope this helps希望这可以帮助

With xctrace for example以 xctrace 为例

   xctrace list  devices | grep -m 1 "iPhone 12" | awk '{print substr($0,length($0)-36,36)}'

I have used below command to get the device id of launched Simulator.我使用下面的命令来获取启动模拟器的设备 ID。

xcrun simctl list devices | grep "(Booted)" | grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})"

We can get the id of specified device by given device name if there are multiple devices are launched如果启动了多个设备,我们可以通过给定的设备名称获取指定设备的 ID

xcrun simctl list devices | grep "(Booted)" | grep "iPhone 12" |grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})"

You can get the list of simulators together with their ID:您可以获得模拟器列表及其 ID:

instruments -s devices

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM