如何使用iOS Simulator模拟磁盘空间不足的情况? [英] How can I use the iOS Simulator to simulate an out of disk space condition?

查看:322
本文介绍了如何使用iOS Simulator模拟磁盘空间不足的情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用iOS模拟器测试磁盘空间不足"情况的实用方法是什么?

What is a practical way to test an "out of disk space" condition using the iOS Simulator?

推荐答案

创建小磁盘映像:

hdiutil create -size 2m -fs HFS+ /tmp/2meg.dmg

将其安装到模拟器应用程序中的相关目录,例如:

Mount it to the relevant directory in your simulator app, e.g.:

hdiutil attach /tmp/2meg.dmg -mountpoint /Users/.../Library/Developer/CoreSimulator/Devices/.../data/Applications/.../Library/Caches

运行应用并执行测试.也可以在应用程序运行时完成此操作.在这种情况下,您可能不想直接将其挂载为CachesDocuments目录,因为这会将当前文件隐藏在那些文件夹中.改为挂载到子目录.如果在不更改应用程序路径的情况下很难做到这一点,请先将图像挂载到其他地方,然后复制数据,然后再将其挂载到非空目录的顶部.

Run app and perform your tests. This can also be done while the app is running. In this case you probably don't want to mount it as Caches or Documents directory directly because this would hide current files in those folders. Mount to a sub-directory instead. If this is not easily possible without changing paths in your app, mount the image somewhere else and copy data over before mounting it on top of the nonempty directory.

要卸载:

hdiutil detach /Users/.../Library/Developer/CoreSimulator/Devi...

但是,请注意,如果移动了挂载点,则分离操作将失败.这总是发生,因为每次运行应用程序时,Apple都会在iOS 8上重命名模拟器目录.在这种情况下,请使用mount命令查找已安装的设备,例如/dev/disk3s1 /Users/.../Library/...,然后使用设备名称而不是安装点来卸载磁盘映像:

However, please note that the detach operation fails if the mount point is moved. This happens all the time because Apple renames simulator directories on iOS 8 every time an app is run. In this case use the mount command to find the device you have mounted, e.g. /dev/disk3s1 /Users/.../Library/..., then unmount the disk image using the device name instead of the mount point:

hdiutil detach disk3s1

这篇关于如何使用iOS Simulator模拟磁盘空间不足的情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆