如何在iPhone模拟器中更改时间和时区?
当前回答
为了截屏,苹果最终通过simctl工具实现了在iOS模拟器的状态栏上覆盖时间的功能(从Xcode 11开始):
xcrun simctl status_bar "iPhone Xs" override --time "21:08"
其他回答
为了截屏,苹果最终通过simctl工具实现了在iOS模拟器的状态栏上覆盖时间的功能(从Xcode 11开始):
xcrun simctl status_bar "iPhone Xs" override --time "21:08"
在更改系统日期时间首选项后,我不得不选择硬件>重置所有内容和设置。 只有在10.3版(SimulatorApp-880.5 CoreSimulator-681.5.4)中,我才这样做。
这是一个老帖子,但它最接近我的问题。我需要模拟欧洲的时区,这个方法适合我。转到“时区”,而不是“日期和时间”。取消选中“使用当前位置自动设置时区”框,并滑动垂直矩形条(上面有蓝点)来模拟系统时间。
以下是至少在iOS 13和Xcode 11中可用的解决方案。(未对以前的版本进行测试) [编辑]这只会改变评论中的状态栏!
默认情况下,iOS模拟器显示Mac上的任何时间,但是,你可以使用Xcode的命令行在终端中使用以下命令来覆盖它:
xcrun simctl status_bar "iPhone 11 Pro Max" override --time '9:41'
将模拟器名称替换为要更改的设备。
对于状态栏,你有这个覆盖:
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.
--batteryState <state>
If specified must be one of 'charging', 'charged', or 'discharging'.
--batteryLevel <int>
If specified must be 0-100.
时间可以是任何字符串。但如果你想让设备显示日期,你需要使用ISO格式。 例如,有效的ISO日期字符串应该是'2007-01-09 t10 . 41:00+01:00'
否则,您可以使用时间参数作为字符串,它将显示您传递的任何内容。
感谢Paul Hudson的原创文章,这里是链接!
在更改系统日期时间首选项后重新启动模拟器,您将看到反映的更改。这对我很管用。
推荐文章
- registerForRemoteNotificationTypes: iOS 8.0及以上版本不支持
- Xcode 4 -在新的Macintosh安装上的配置文件上“没有找到有效的签名标识”错误
- 新的自动引用计数机制是如何工作的?
- 如何测试对象在Objective-C中的类?
- Xcode +删除所有断点
- 是否有可能禁用浮动头在UITableView与UITableViewStylePlain?
- 从Cocoa应用程序执行一个终端命令
- Swift:理解// MARK
- Swift编译器错误:“框架模块内的非模块化头”
- 从父iOS访问容器视图控制器
- 如何在JavaScript中获得时区名称?
- 自定义dealloc和ARC (Objective-C)
- 调整UITableView的大小以适应内容
- 在代码中为UIButton设置一个图像
- UICollectionView中的单元格间距