I have downloaded a json file (data.json
) using NSURLSession. I am trying to access this file from a local html file (main project folder) myfile.html
which is displayed via UIWebView. From NSLog I have identified the temp file location is here:
file:///Users/administrator/Library/Developer/CoreSimulator/Devices/166B438D-4F67-448C-B0E5-B32438DA3BF9/data/Containers/Data/Application/FCA61482-BC5D-4804-91F8-891EAB4DB145/tmp/CFNetworkDownload_g6961Q.tmp
My question is how should I access this temp file from the local 'top level' html file, using a relative path?
More generally therefore - how does one access the iOS application file structure from such a top level (relative to the project) html file?
Some background info:
When I manually copy
data.json
to XCode and access it frommyfile.html
using the relative path'data.json'
it works.The download code is:
NSURL *URL = [NSURL URLWithString:@"http://myurl.com/data.json"]; NSURLRequest *request = [NSURLRequest requestWithURL:URL]; NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDownloadTask *downloadTask = [session downloadTaskWithRequest:request completionHandler: ^(NSURL *location, NSURLResponse *response, NSError *error) { }
The reason I am doing this with NSURLSession is that I can't do it with Javascript in the html file since it is a cross domain request.
EDIT: Thanks for the helpful answers about adding HTML as a string into the UIWebView. I can see that trying to reference a temp file from the local HTML file is a bit unwieldly and may run counter to Apple's preference of not exposing filepaths - but I am still interested in a definitive answer on whether it can be done.