6 Replies
      Latest reply on Nov 13, 2015 10:29 AM by celedonio
      AdcOlie Level 1 Level 1 (0 points)

        Ok, no permanent storage -- I get it.  But is there a place I can use for temporary storage?  Like, if I want to download a save-game state before parsing it into memory.  Or if I want to write the game-state to a file, so I can apply zip and upload it.

         

        Yes, I could probably do all of this in memory, but my current infrastructure is set up to use temporary files, and I'd love to just continue to use that, while only changing the tmpDir variable -- that'd be super sweet.

         

        Is there any temporary directory to which I can write?

         

        Thanks!

        • Re: tvOS: Temporary storage?
          justin.voss Apple Staff Apple Staff (260 points)

          You can write data to the Caches directory and the data should stay there as long as your app is running. But when your app exits, that data could be deleted by the system, so be prepared for it to be gone when your app launches again.

            • Re: tvOS: Temporary storage?
              TidBits Apple Staff Apple Staff (1,645 points)

              The temporary directory is also availalble, but just as Justin described, it can be purged when your app is no longer running. But for the use case you describe, it should work just fine.

                • Re: tvOS: Temporary storage?
                  loretoparisi Level 1 Level 1 (10 points)

                  So to access Temporary folder I have to do

                   

                  NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSSstring stringWithFormat:@"%d", appBundleId];

                   

                  and the Cache folder like

                   

                  NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];

                  NSString *cacheFile = [cachesPath stringByAppendingPathComponent:@"file.plist"];

                   

                  but there is no way to access to the Documents folder like

                   

                  NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

                  NSString *documentsDir = [documentPaths objectAtIndex:0];

                   

                  So, supposed the that app or a embedded framework needs to create da Sqlite database, there's no way to make it persistent at this time.

                • Re: tvOS: Temporary storage?
                  MadDavid Level 1 Level 1 (0 points)

                  Are you sure? When I have tried to save to a file to cache directory I don´t get any error, but the file is not saved.

                    • Re: tvOS: Temporary storage?
                      loretoparisi Level 1 Level 1 (10 points)

                      Yes pretty sure. I have downloaded the xcappdata from the AppleTV and I can see the sqlite database inside.
                      I'm working with fallbacks like

                       

                       

                       

                          NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

                          NSString *documentsDir = [documentPaths objectAtIndex:0];

                        NSError *dbError=nil;

                          NSString *dbFolder = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"db.%@",APP_DATASTORE_VERSION]];

                          if ( ![[NSFileManager defaultManager] fileExistsAtPath:dbFolder] ) { // this works in iOS / watchOS

                              [[NSFileManager defaultManager] createDirectoryAtPath:dbFolder withIntermediateDirectories:YES attributes:nil error:&dbError]; /

                          }

                        if(dbError!=nil) { // this works in tvOS

                              dbError=nil;

                              NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];

                              dbFolder = [cachesPath stringByAppendingPathComponent:[NSString stringWithFormat:@"db.%@",APP_DATASTORE_VERSION]];

                              [[NSFileManager defaultManager] createDirectoryAtPath:dbFolder withIntermediateDirectories:YES attributes:nil error:&dbError]; /

                          }