I have an iOS app that basically copies the sample app and swaps a few things out.
When I use a .xml included in the project, everything loads/functions totally fine. But I'm trying to have it load the .xml and .dat from a server on startup, and use that as the tracking info.
So, the app starts, I download the files, and save them locally. This works great. Then, I call loadObjectTrackerDataSet:(NSString *)dataFile with the URL to the locally saved .xml file (the .dat file is named/located identically, except for the file extension).
Here's the code that deals with that:
if(dataFile && ![dataFile isEqualToString:@""]) //data file URL exists! use absolute location
{
if(!tDataSet->load([dataFile cStringUsingEncoding:NSASCIIStringEncoding], Vuforia::STORAGE_ABSOLUTE))
{
NSLog(@"Vuforia: ERROR: failed to load custom data set");
objectTracker->destroyDataSet(tDataSet);
tDataSet = NULL;
}
}
else //data file URL doesn't exist, load default from resources dir
{
NSString *defaultDataFile = [NSString stringWithFormat:@"MGG_2017_01_07.xml"];//@"StonesAndChips.xml"];
if(!tDataSet->load([defaultDataFile cStringUsingEncoding:NSASCIIStringEncoding], Vuforia::STORAGE_APPRESOURCE))
{
NSLog(@"Vuforia: ERROR: failed to load default data set");
objectTracker->destroyDataSet(tDataSet);
tDataSet = NULL;
}
}
So if I pass in an empty/null string, it loads a default .xml that's packaged with the app. This works fine. But if I pass in a non-empty string, it tries to load the datafile from the absolute location that I passed in (in this case, file:///var/mobile/Containers/Data/Application/954551B4-4105-44A0-8D8B-EB98F957EF55/Library/7978/vuforiadb.xml ). But this fails.
The documentation doesn't offer much help for when/why it would fail. What am I missing/doing wrong?
Some thoughts:
- Is this the "absolute URL" expected by Vuforia::STORAGE_ABSOLUTE?
- Does its name need to conform to any weird quirks?
- Does the location of the .dat need to be anything special?
- Does it fundamentally have a problem loading the info from anywhere but the assets folder in the resources bundle?
- Sort Posts
- 2 replies
- Last post
Dynamically loading .xml and .dat failing
Dynamically loading .xml and .dat failing
Hi ,
I faced this problem, but now i got solution. Your .dat and .xml is not downloading properly in document directory/local store.
you need to download .dat and .xml.
I hope so, It will help you both.
I used following code for downloading .dat and .xml.:-
-(void)downloadFileforXML:(NSString *)xml_url
{
NSString *documentDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
filePath = [documentDir stringByAppendingPathComponent:@"result.xml"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:xml_url]];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if (error) {
NSLog(@"Download Error:%@",error.description);
}
if (data) {
[data writeToFile:filePath atomically:YES];
NSLog(@"File is saved to %@",filePath);
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setValue:filePath forKey:@"xmlFilePath"];
}
}];
}
-(void)downloadFileforDat:(NSString *)dat_url
{
NSString *documentDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *filePath = [documentDir stringByAppendingPathComponent:@"result.dat"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:dat_url]];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if (error) {
NSLog(@"Download Error:%@",error.description);
}
if (data) {
[data writeToFile:filePath atomically:YES];
NSLog(@"File is saved to %@",filePath);
}
}];
}
I need to know too.