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.
Luckily, Xcode offers a way to simulate location on every run. To simulate location on every run, we set a location in an Xcode scheme option. Select Product Menu > Scheme > Edit Scheme... or Click on scheme name and select Edit Scheme. Select Run on the left panel, then select Options tab. Make sure "Allow Location Simulation" is checked.
With your preferred date and time locked in, hit the Fly button, and you’ll load into your destination at the selected date and time. You can also change the date and time while you’re already flying around.
To create a movement, you create a GPX file with multiple waypoints. Time ( <time>) is needed in this case to simulate realistic movement. Xcode will interpolate movement at a rate of speed based on the time elapsed between each waypoint. If you do not provide a time element, then Xcode will use a fixed rate of speed.
Xcode will interpolate movement at a rate of speed based on the time elapsed between each waypoint. If you do not provide a time element, then Xcode will use a fixed rate of speed. Waypoints must be sorted by time in ascending order. This is an example of a GPX file that simulate movement between two waypoints.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With