Is it even possible for one iOS app to access another app's Caches directory?

孤街浪徒 提交于 2019-12-25 15:55:40

问题


I'm writing a unit test with GHUnit. I would like to check if a file is being generated in the Caches directory within the Library directory of another app. Is this feasible, or are apps prevented from accessing each others' Library directories? And if so, are there any possible workarounds for creating a unit test for this? Could I possibly store the generated file in a different directory, such as Documents, or would that not help?


回答1:


I don't understand the context that you're attempting to unit test, so maybe my answer is wrong, but what I get is that you want to access your other app because GHUnit builds as a separate app.

There should be no reason to do this - instead of beating the sandbox problem, let's go around the whole issue.

Why not run whatever cache-creating code you are trying to test in the first place from the test target app, and then check the Libary/Cache directory of your bundle?

That's all there should be to it.




回答2:


On device it is not possible at all. In simulator you can theoretically do it if you know the random UUID that names the directory that the application is installed in.

But I would highly discourage you from even trying. Instead make the code you intend to test stand enough of it's own to be testable. A unit test that verifies if another application behaves is on it's own almost as useless as a unit test that verifies that you call an API with the correct arguments.




回答3:


Apps can only access their own folders within their sandbox. Is your unit testing app separate from your app that you want to verify the cache contents of?




回答4:


No, what you would need to do is use url prefixes and have the methods to do whatever you need done registered by that application on install.



来源:https://stackoverflow.com/questions/5954040/is-it-even-possible-for-one-ios-app-to-access-another-apps-caches-directory

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