如何更改iPhone模拟器中的时间?我希望手机上的其他应用程序能够看到与当前应用程序不同的时间。
答案 0 :(得分:4)
旧问题,现代答案:
With Xcode 11, Apple shipped new features for the simctl tool,通过覆盖状态栏值,您可以对模拟器的外观进行更多控制。
找到正确的设备
命令xcrun simctl list
lists 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.
答案 1 :(得分:3)
在主机Mac上更改系统时间。模拟器运行一个单独的用户空间,但共享内核,因此它没有与主机不同时间的概念。