I am running an ionic
project's ios build app.xcproj
in xcode
.
I am downloading json files from server in the following location: /var/mobile/Containers/Data/Application/63E66EE9-9A1B-4D4D-AEF6-F8C54D159ED0/Library/NoCloud/MyApp/Timing/DTS.json
and I have checked I have files by printing:
NSURL *urlDTS = [NSURL fileURLWithPath: DTS_Path];
NSString *fileContentDTS = [NSString stringWithContentsOfURL:urlDTS encoding:NSUTF8StringEncoding error:nil];
NSLog(@"Json data is here of DTS %@", fileContentDTS);
This prints whole file ok, after that when i get the resource path for further operations it shows null
NSString *filePathDTS = [[NSBundle mainBundle] pathForResource:getParameterDTSValueName ofType:@"json"];
NSLog(@"This is the dts path %@", filePathDTS);
Even I have retrieved the files location as /var/mobile/Containers/Data/Application/63E66EE9-9A1B-4D4D-AEF6-F8C54D159ED0/Documents/DTS.json
by following this Link:
NSString *documentdir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *tileDirectory = [documentdir stringByAppendingPathComponent:@"xxxx/DTS"];
NSLog(@"Tile Directory: %@", tileDirectory);
Update
This is what file contains: [{"value":0}]
NSURL *libraryDirURL = [[NSFileManager.defaultManager URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject];
NSURL *urlDTSK = [libraryDirURL URLByAppendingPathComponent:@"NoCloud/MyApp/MyFolder/DTS.json"];
NSString *filePathDTS = [NSString stringWithContentsOfURL:urlDTSK encoding:NSUTF8StringEncoding error:nil];
NSLog(@"This is Dts PATH %@", filePathDTS);
NSData *dataDTS = [NSData dataWithContentsOfFile:filePathDTS];
NSLog(@"here is DTS data %@", dataDTS); //this shows null
NSDictionary *jsonDTS = [NSJSONSerialization JSONObjectWithData:dataDTS options:kNilOptions error:nil];
NSLog(@"here is jason DTS %@", jsonDTS);
NSMutableArray *DTSvalue = [jsonDTS valueForKeyPath: @"Value"];
DTSValueIs = DTSvalue[0];
NSLog(@"here is DTS Value first%@", DTSvalue[0]);
NSLog(@"here is DTS value is%@", DTSValueIs);
This shows This is Dts contents [{"value":0}]
2018-06-11 17:04:40.940006+0500 Muslims 365[3356:819935] here is DTS data (null)
Please guide me how can i retrieve data from json file by providing resource in main bundle??? as it shows null.