Start a new topic
Solved

iOS wikitude html and js file storage

Are storing files outside the app bundle in iOS a problem with the SDK? I store them at run time in the XCode NSCachesDirectory ( have also tried NSLibraryDirectory), and before sending it to the AugmentedRealityExperience alloc init method



 self.augmentedRealityExperience = [[WTAugmentedRealityExperience alloc] initWithTitle:title

 groupTitle:groupTitle

 URL:indexFileURL

 requiredFeatures:requiredFeatures

 startupParameters:startupParameters

 requiredViewControllerExtension:nil];


the above returns an object and  I also checked that the file exists first. The architect world though fails to load via the delegate method .. architectView didFailToLoadArchitectWorldNavigation:.. method:


did fail to load navigation 'navigation: 

original URL: '

file:///var/mobile/Containers/Data/Application/AD11E025-AF00-4E16-9F20-31E311B50F2D/Library/TempFileCache/ar_worlds/atm_locator/index.html'


I know with the sample the files are in the app bundle but I want to get my files from a server in case I need to dynamically change them, and can't put them into the apps bundle at run time.


Many thanks


Hi n n,

In general that should work.

Which API do you use to get the URL to the index.html file? It should be something similar to

[[NSBundle mainBundleURLForResource:@"index" withExtension:@"html"subdirectory:@"YOUR_SUBDIRECTORY"]];

 

Best regards,

Andreas

You can't use NSBundle mainBundle to write to at run time. That is only for static files as the SDK example has . My files are written to  NSCachesDirectory and I get them using 


NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject;


Have tried the above also with NSLibraryDirectory or NSDocumentDirectory but all still give the same error


NSBundle URL:  file:///var/containers/Bundle/Application/

Caches URL:      file:///var/mobile/Containers/Data/Application/


Can you please try your side?

Hi n n,

I just mentioned NSBundle here because the return value of that method is what the WTArchitectView -load method is expecting.

Can you please post the complete code that you use to get the URL to your .html file? 


Best regards,

Andreas

  

   NSURL *indexFileURL = nil;

    NSLog(@"APP_DELEGATE PATH: %@", APP_DELEGATE.dataManager.tempCachePath);
    
    for (ARDataEntity *arDataEntity in data)
    {
        NSURL *url = [NSURL fileURLWithPath:[arDataEntity fileNameWithPath] relativeToURL:APP_DELEGATE.dataManager.tempCachePath];


        if ([[url lastPathComponent] isEqual: @"index.html"])
        {
            if ([[NSFileManager defaultManager] fileExistsAtPath: [arDataEntity fileNameWithPath]])
            {
                NSLog (@"path %@",  url); //works
            }
            
            indexFileURL = url;

 
            self.tempfile = url;
            NSLog (@"INDEX file path: %@", indexFileURL);
		  //  /var/mobile/Containers/Data/Application/71BBD047-53DE-4DD9-843C-EC83E42D2298/Library/Caches/TempFileCache/ar_worlds/locator/index.html

            break;
        }
    }
    


    self.augmentedRealityExperience = [[WTAugmentedRealityExperience alloc] initWithTitle:title
                                                                               groupTitle:groupTitle
                                                                                      URL:indexFileURL
                                                                         requiredFeatures:requiredFeatures
                                                                        startupParameters:startupParameters
                                                          requiredViewControllerExtension:nil];
    [self startLocationUpdatesForPoiInjection];
    

  

Hi n n,

The important point here is the format of the url that you're giving to the SDK. What the SDK (the internal UIWebView) needs is a URL in the following format:

file:///var/containers/Bundle/Application/5F1B8DC9-89F4-4E12-B90B-446BB5A27A13/DevApplication.app/ImageOnTarget/index.html

The NSBundle usually returns such urls.

code: [[NSBundle mainBundleURLForResource:@"index" withExtension:@"html" subdirectory:@"ImageOnTarget"]

You just need to use a Cocoa API that return a file url in the same format but pointing to the e.g. tmp directory.


Your log from line 22 outputs a url that is missing the `file:///` prefix. You get such a url with the following code:

NSURL *fileURL = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"architect/ImageOnTarget/index.html"isDirectory:NO];

output: file:///private/var/mobile/Containers/Data/Application/1D667591-4DFA-4679-BA6E-DD2DF783D1EC/tmp/architect/ImageOnTarget/index.html


I was able to load an Architect World from the temporary directory using the [NSURL fileURLWithPath] method.

architect view finished load of world at url: file:///private/var/mobile/Containers/Data/Application/E10409CB-442E-48D7-BE98-6E85E6F68EF8/tmp/architect/ImageOnTarget/index.html


Can you try using the +fileURLWithPath method in your project? You can also implement the  -architectView: didFailToLoadArchitectWorldNavigation:withError: method and log the error description to get an idea why it's not working for you.


Please let me know if the +fileURLWithPath method is working for you.


Best regards,

Andreas



Login or Signup to post a comment