Load Document files like .pfd,.txt,.doc etc

Instead of web pages, we can also load the document files into iOS WebView like .pdf, .txt, .doc etc.. loadData method is used to load NSData into webview.

Swift

//Assuming there is a text file in the project named "home.txt".let localFilePath = NSBundle.mainBundle().pathForResource(“home”, ofType:”txt”);
let data = NSFileManager.defaultManager().contentsAtPath(localFilePath!);
webview.loadData(data!, MIMEType: “application/txt”, textEncodingName:”UTF-8" , baseURL: NSURL())

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mr.Javed Multani

Mr.Javed Multani

296 Followers

iOS Developer, Triple graduated, Passionate, Love workout, blogger