【发布时间】:2017-02-16 17:20:13
【问题描述】:
如何在 iPhone 模拟器中更改时间?我希望我手机上的其他应用程序看到与当前不同的时间。
【问题讨论】:
标签: xcode time ios-simulator
如何在 iPhone 模拟器中更改时间?我希望我手机上的其他应用程序看到与当前不同的时间。
【问题讨论】:
标签: xcode time ios-simulator
老问题,现代答案:
With Xcode 11, Apple shipped new features for the simctl tool,它允许您通过覆盖状态栏值来更好地控制模拟器的外观。
找到正确的设备
命令xcrun simctl listlists the currently installed simulators and gives their status:
% xcrun simctl list
== Device Types ==
<list of device types>
== Runtimes ==
<list of runtimes>
== Devices ==
-- iOS 13.5 --
iPhone 11 (A2A694CF-8DA3-4371-AD2D-A2592A5C770C) (Shutdown)
iPhone 11 Pro (F36583E8-6833-4526-8622-CE24022BE876) (Booted)
iPhone 11 Pro Max (82029941-193B-423E-BE89-DD3E1C0B12E6) (Shutdown)
这个命令的输出很长,所以 NSHipster 很好地提供了一个在their simctl article 中打印当前启动设备的UDID 的命令:
$ xcrun simctl list devices | \
grep "(Booted)" | \
grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})"
9FED67A2-3D0A-4C9C-88AC-28A9CCA44C60
获取适当的设备 UDID 并将其传递给以下命令以更改模拟器的当前时间:
% xcrun simctl status_bar F36583E8-6833-4526-8622-CE24022BE876 override --time "9:41"
%
运行xcrun simctl help status_bar 将显示全方位的选项:
$ xcrun simctl help status_bar
Set or clear status bar overrides
Usage: simctl status_bar <device> [list | clear | override <override arguments>]
Supported Operations:
list
List existing overrides.
clear
Clear all existing status bar overrides.
override <override arguments>
Set status bar override values, according to these flags.
You may specify any combination of these flags (at least one is required):
--time <string>
Set the date or time to a fixed value.
If the string is a valid ISO date string it will also set the date on relevant devices.
--dataNetwork <dataNetworkType>
If specified must be one of 'wifi', '3g', '4g', 'lte', 'lte-a', or 'lte+'.
--wifiMode <mode>
If specified must be one of 'searching', 'failed', or 'active'.
--wifiBars <int>
If specified must be 0-3.
--cellularMode <mode>
If specified must be one of 'notSupported', 'searching', 'failed', or 'active'.
--cellularBars <int>
If specified must be 0-4.
--operatorName <string>
Set the cellular operator/carrier name. Use '' for the empty string.
--batteryState <state>
If specified must be one of 'charging', 'charged', or 'discharging'.
--batteryLevel <int>
If specified must be 0-100.
【讨论】:
xcrun simctl status_bar "iPhone 11 Pro Max" override --time "7:11"
在主机 Mac 上更改系统时间。模拟器运行一个单独的用户空间,但共享内核,因此它没有与主机不同时间的概念。
【讨论】: