Changing the time and date in Xcode simulator

百般思念 提交于 2020-06-13 19:11:08

问题


How to change the time in the iPhone simulator ? I want the other apps on my phone to see a different time than the current one.


回答1:


Change your system time on the host Mac. The Simulator runs a separate userspace but shares the kernel so it doesn't have a notion of a different time from the host.




回答2:


Old question, modern answer:

With Xcode 11, Apple shipped new features for the simctl tool, which allows you to have a bit more control over what the simulators look like by overriding status bar values.

Finding the correct device
The command 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) 

The output of this command is very long so NSHipster was nice enough to provide a command that prints the UDID of the currently booted device in their simctl article:

$ 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 

Grab the appropriate device UDID and pass that into the following command to change the simulator's current time:

% xcrun simctl status_bar F36583E8-6833-4526-8622-CE24022BE876 override --time "9:41"
%

Running xcrun simctl help status_bar will show a full range of options:

$ 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.


来源:https://stackoverflow.com/questions/39921805/changing-the-time-and-date-in-xcode-simulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!