iOS沙盒机制

来源:互联网 发布:mac安装adobe 编辑:程序博客网 时间:2024/05/17 05:10

原文地址:http://blog.csdn.net/weasleyqi/article/details/31502459

IOS中的沙盒机制(SandBox)是一种安全体系,它规定了应用程序只能在为该应用创建的文件夹内读取文件,不可以访问其他地方的内容。所有的非代码文件都保存在这个地方,比如图片、声音、属性列表和文本文件等。
1.每个应用程序都在自己的沙盒内
2.不能随意跨越自己的沙盒去访问别的应用程序沙盒的内容
3.应用程序向外请求或接收数据都需要经过权限认证

显示和隐藏文件夹的方法:
显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool true
隐藏Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool false

然后重新启动Finder,点击屏幕左上角苹果标志——强制退出——选择Finder然后点击重新启动,这个时候在重新打开Finder就可以看到被隐藏的文件了。

模拟器里的内容路径如下:




每个应用程序都有自己独有的目录:
/var/mobile/Applications/UUID
当应用程序安装时,UUID随机产生;(包括每次从xcode去run应用,所以调试的时候要注意!

当删除应用程序重新安装的时候会重新生成目录


每个app目录下都有以下几个文件夹:

Documents/

Library/

Library/Caches

Library/Preferences

tmp/

.app


每个文件(文件夹)的功能如下:

.app/,这个就是可运行的应用文件,带有签名的文件包,包含应用程序代码和静态数据;
Documents/
:Use this directory to store critical user documents and app data files. Critical data is any data that cannot be recreated by your app, such as user-generated content.
The contents of this directory can be made available to the user through file sharing. The contents of this directory are backed up by iTunes.
:苹果建议将程序中创建的或在程序中浏览到的文件数据保存在该目录下,iTunes备份和恢复的时候会包括此目录;
Library/
:This directory is the top-level directory for files that are not user data files. You typically put files in one of several standard subdirectories but you can also create custom subdirectories for files you want backed up but not exposed to the user. You should not use this directory for user data files.
The contents of this directory (with the exception of the Caches subdirectory) are backed up by iTunes.
For additional information about the Library directory, see “The Library Directory Stores App-Specific Files.”
:应用程序支持文件;
Library/Preferences/ :存储程序的默认设置或其它状态信息;
Library/Caches/:存放缓存文件,iTunes不会备份此目录,此目录下文件不会在应用退出删除;当系统清理磁盘空间的时候会删除里面的内容。
tmp/
:Use this directory to write temporary files that do not need to persist between launches of your app. Your app should remove files from this directory when it determines they are no longer needed. (The system may also purge lingering files from this directory when your app is not running.)
In iOS 2.1 and later, the contents of this directory are not backed up by iTunes.
:创建和存放临时文件的地方,应用程序成功启动,临时文件不需要持久保存。

-----------------------分割线------------------------


看了上面这段,下面这个提问,就显而易见了。


原文地址:https://segmentfault.com/q/1010000005109966


项目每Run一下,Documents目录就变了,就像重新安装了一个App一样? 

0

以前我记得每次Run的时候还是会对应原来的App,Ducoments文件都是一样的。
如今为啥变成这样子了?
到时候是不是用户下载更新的时候也会变了?
这样子我存在Documents的数据就都没了?

  • 2016年05月12日提问 
  • 评论 
  • 邀请回答 
  • 编辑 
默认排序时间排序

1个回答

0

首先,在我这一直都是如此,每次运行,Documents路径会被修改。
其次,不存在数据消失,除非是删除App,苹果只是每次回动态修改文件夹的名称,并不是一个全新的文件夹。
这只是苹果的安全特性,并不会影响你的正常使用和开发。

0 0
原创粉丝点击