iOS-应用程序沙盒机制(SandBox)
2015-12-27 00:00
691 查看
摘要: iOS程序的沙盒机制SandBox,是一种安全机制,它规定了应用程序只能在为该应用创建的文件夹内读取文件,不可以访问其他地方的内容。
(1) 每个应用程序都在自己的沙盒内,都有独立的文件系统
(2) 不能随意跨越自己的沙盒去访问别的应用程序沙盒中的内容
(3) 应用程序向外请求或接收数据都需要经过权限认证
Documents,苹果建议将程序中创建的或在程序中浏览到的文件数据保存在该目录下,iTunes备份和恢复的时候会包括此目录;
Library,存储程序的默认设置或其它状态信息;
Library/Caches:存放缓存文件。iTunes不会备份此目录,此目录下文件不会在应用退出删除;
Library/Preferences: 存储程序的默认设置。基于NSUserDefaults的首选项设置便存储在这个里。
tmp,创建和存放临时文件的地方,iTunes备份和恢复的时候不会包括此目录。
代码示例:
http://blog.csdn.net/wzzvictory/article/details/18269713
iOS应用程序沙盒
iOS程序的沙盒机制SandBox,是一种安全机制,它规定了应用程序只能在为该应用创建的文件夹内读取文件,不可以访问其他地方的内容。 所有的非代码文件都保存在这个地方,比如图片、声音、属性列表和文本文件等。(1) 每个应用程序都在自己的沙盒内,都有独立的文件系统
(2) 不能随意跨越自己的沙盒去访问别的应用程序沙盒中的内容
(3) 应用程序向外请求或接收数据都需要经过权限认证
应用程序的目录
默认情况下,每个沙盒有三个文件夹,Documents、Library、tmpDocuments,苹果建议将程序中创建的或在程序中浏览到的文件数据保存在该目录下,iTunes备份和恢复的时候会包括此目录;
Library,存储程序的默认设置或其它状态信息;
Library/Caches:存放缓存文件。iTunes不会备份此目录,此目录下文件不会在应用退出删除;
Library/Preferences: 存储程序的默认设置。基于NSUserDefaults的首选项设置便存储在这个里。
tmp,创建和存放临时文件的地方,iTunes备份和恢复的时候不会包括此目录。
代码示例:
// // ViewController.swift // import UIKit class RootViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. // 1 Home 目录,即沙河目录 ~/ let path1 = NSHomeDirectory(); print("path1 = \(path1)") // 2 Documents 目录 ~/Documents let path2 = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, false).first! print("path2 = \(path2)") // 3 Library 目录 ~/Library let path3 = NSSearchPathForDirectoriesInDomains(.LibraryDirectory, .UserDomainMask, true).first! print("path3 = \(path3)") // 4 Caches 目录 ~/Library/Caches let path4 = NSSearchPathForDirectoriesInDomains(.CachesDirectory, .UserDomainMask, true).first! print("path4 = \(path4)") // 5 tmp 目录 ~/tmp/ let path5 = NSTemporaryDirectory() print("path5 = \(path5)") } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
参考
https://developer.apple.com/library/mac/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW2http://blog.csdn.net/wzzvictory/article/details/18269713
相关文章推荐
- 微软发布令牌漏洞公告:可绕过 Chromium 沙盒执行任意代码
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 讲解iOS开发中基本的定位功能实现
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- 浅析iOS应用开发中线程间的通信与线程安全问题
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- IOS 改变键盘颜色代码
- 举例详解iOS开发过程中的沙盒机制与文件
- Android和IOS的浏览器中检测是否安装某个客户端的方法
- 分享一个iOS下实现基本绘画板功能的简单方法