无标题文章

2017-05-14  本文已影响0人  6cf9a0b2369d

// 沙盒:每个应用程序都是一个沙盒,只能在自己的沙盒中存取资源,在ios8以后放开某些文件夹的权限可以被外界访问

//沙盒中目录结构

//document

//library

//cache 缓存

//prepe

//tmp

//1.搜索的路径2.主机3.文件路径是否为全路径

let doucuments =  NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)

print(doucuments[0])

print("11"+NSHomeDirectory())

//lib

let libs = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)

print("lib="+libs[0])

//catche

let catches = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)

print("catches="+catches[0])

//prefer

let prefer = libs[0]+"/Preferences"

print("prefer="+prefer)

//获取temp目录 获取到沙盒目录 在拼接tmp目录

let tmp = NSHomeDirectory()+"/tmp"

//let tmp1 = NSTemporaryDirectory()

print("tmp="+tmp)

//        // 加载资源

let path = Bundle.main.path(forResource: "index", ofType: "html")

let html = try! String(contentsOfFile: path!)

// 创建webview

let webView = UIWebView(frame: self.view.frame)

self.view.addSubview(webView)

webView.loadHTMLString(html, baseURL: nil)

//        let weView = UIWebView(frame: self.view.frame)

//

//        let url = NSURL(fileURLWithPath:path!)

//        let request = URLRequest(url: url as URL)

//        self.view.addSubview(weView)

//        weView.loadRequest(request)

//        self.view.addSubview(weView)

}

上一篇 下一篇

猜你喜欢

热点阅读