Search code examples
iosxcodedownloadaugmented-reality

How to download dataset for Vuforia app?


I'm developing sample apps from Vuforia SDK 1.5.9 in Xcode 4.2 with iOS 5.1. In that version I could not make my trackable datasets on my own - I have to use online solution from Qualcomm. Does anyone know or have anyone tried to download datasets from remote location? So you generate them as usual but download them into app from server, so I can for example choose which one to download and use on fly?

Yesterday I've given it a quick try with this:

-(void)setupMarkers{
    NSString *filePathX;
    //connect to the remot location
    NSURL *urlD = [NSURL URLWithString:[NSString stringWithFormat:@"%@/frames.dat",kURLServer]];
    NSData *urlData = [NSData dataWithContentsOfURL:urlD];
    if ( urlData )
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];  

        NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"frames.dat"];
        [urlData writeToFile:filePath atomically:YES];
    }
    NSURL *urlX = [NSURL URLWithString:[NSString stringWithFormat:@"%@/frames.xml",kURLServer]];
    NSData *urlDataX = [NSData dataWithContentsOfURL:urlX];
    if ( urlDataX )
    {
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];  

        NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"frames.xml"];
        [urlDataX writeToFile:filePath atomically:YES];
        filePathX = filePath;
    }
    //put them into markersArray
    [self.markersArray addObject:filePathX];
}

I know it is ugly, but as I said it was a quick try, but it didn't work at all. I know there is new Vuforia SDK 2.0 with clouds and stuff, but afaik I would have to use iOS6 & Xcode 4.5 - which is not a solution for me right now.


Solution

  • Actually my "quick try" wasn't that bad after all :) Here's what i did:

    1. wrote a method -(void)setupMarkers in which I dwonload .dat and .xml files (like in question)
    2. in QCARUtils.mm I changed in - (QCAR::DataSet *)loadDataSet:(NSString *)dataSetPath one line:

      // Load the data set from the App Bundle
      // If the DataSet were in the Documents folder we'd use STORAGE_ABSOLUTE and the full path
      if (!theDataSet->load([dataSetPath cStringUsingEncoding:NSASCIIStringEncoding], QCAR::DataSet::STORAGE_ABSOLUTE))//STORAGE_APPRESOURCE)){
      ...
      }
      

    works like a charm :)

    p.s. I'll wait a while so if anyone will come up with better answer ;)