Creating directory within Application Support, and preventing iCloud backupCreating and saving blurred...

Dilemma of explaining to interviewer that he is the reason for declining second interview

Recrystallisation of dibenzylideneactone

Citing paywalled articles accessed via illegal web sharing

How to deal with an incendiary email that was recalled

Do authors have to be politically correct in article-writing?

Caruana vs Carlsen game 10 (WCC) why not 18...Nxb6?

Placing an adverb between a verb and an object?

What is the wife of a henpecked husband called?

Chess tournament winning streaks

Does Windows 10's telemetry include sending *.doc files if Word crashed?

Why are the books in the Game of Thrones citadel library shelved spine inwards?

Check if the digits in the number are in increasing sequence in python

Is there any differences between "Gucken" and "Schauen"?

Cryptic with missing capitals

What kind of hardware implements Fourier transform?

Is there some relative to Dutch word "kijken" in German?

How to avoid being sexist when trying to employ someone to function in a very sexist environment?

What to do when being responsible for data protection in your lab, yet advice is ignored?

Disable the ">" operator in Rstudio linux terminal

How do I say "Brexit" in Latin?

Why does String.replaceAll() work differently in Java 8 from Java 9?

Book where aliens are selecting humans for food consumption

What is the most triangles you can make from a capital "H" and 3 straight lines?

Why is "points exist" not an axiom in geometry?



Creating directory within Application Support, and preventing iCloud backup


Creating and saving blurred screenshots in iOSExport class instances to a string (for sharing, backup) and importing themInterview coding challenge for iOS Part 2 - the application in Objective-C and SwiftLog in user through json and display the application













2












$begingroup$


I'm using react native to build an iOS app, but have little to no experience in obj C or iOS development. The app I'm building has a bunch of content files that aren't user specific, will be downloaded from some CDN, and will (mostly) be behind a paywall. As I understand it, the best place for this would be somewhere within Application Support (the Cache dir doesn't seem to fit the bill because this is more about allowing users to download content for offline use than caching per se. Also, I think there's no guarantees about the lifetime of files in the Cache dir(?).). Also, I want to make sure that those content files aren't backed up to iCloud or anywhere else; and that they're not accessible by the user or other apps.



I have two questions:




  1. Does that placement for the content fit with iOS recommendations/best practices?


  2. Because I have little obj c/iOS experience, I'd be super grateful if you lovely people could cast your eyes over the code and review it?



// *** blah.h
#import <React/RCTBridgeModule.h>

@interface Blah : NSObject <RCTBridgeModule>
@end


// *** blah.m
#import "Blah.h"

@implementation Blah

RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(createAppDataPath:(NSString *)namespace findEventsWithResolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject){

NSUInteger length = [namespace length];

if (length < 1) {
reject(@"namespace_invalid", @"Namespace param should be non-empty string", nil);
return;
}

// ref: https://stackoverflow.com/a/17430820/1937302

@try {

NSString *appSupportDir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject];
NSString *cacheDir = [appSupportDir stringByAppendingString: [NSString stringWithFormat:@"/%@", namespace]];

// check for existence of directory:
BOOL isDir;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:cacheDir isDirectory:&isDir];

if (!exists) {
NSError *error = nil;
// if not present, create it:
BOOL result = [[NSFileManager defaultManager] createDirectoryAtPath:cacheDir withIntermediateDirectories:YES attributes:nil error:&error];
if (!result) {
reject(@"cant_create", @"Can't create directory", error);
return;
}
} else if (!isDir) {
reject(@"non_directory_path_exists", @"Path already exists as a non-directory", nil);
return;
}

// now mark the directory as excluded from iCloud backups:
NSURL *url = [NSURL fileURLWithPath:cacheDir];
NSError *error = nil;
BOOL result = [url setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:&error];

if (!result) {
reject(@"cant_exclude_from_backups", @"Can't exclude from backups", error);
return;
}

resolve(cacheDir);

}
@catch(NSException *exception) {
// TODO: capture information from exception and pass to rejection?
// ref: https://stackoverflow.com/questions/43561531/how-to-convert-an-exception-into-an-nserror-object
// ref: https://stackoverflow.com/a/4654759/1937302
// ref: https://developer.apple.com/documentation/foundation/nsexception
reject(@"exception", @"An exception has occurred", nil);
}
}

@end









share|improve this question











$endgroup$

















    2












    $begingroup$


    I'm using react native to build an iOS app, but have little to no experience in obj C or iOS development. The app I'm building has a bunch of content files that aren't user specific, will be downloaded from some CDN, and will (mostly) be behind a paywall. As I understand it, the best place for this would be somewhere within Application Support (the Cache dir doesn't seem to fit the bill because this is more about allowing users to download content for offline use than caching per se. Also, I think there's no guarantees about the lifetime of files in the Cache dir(?).). Also, I want to make sure that those content files aren't backed up to iCloud or anywhere else; and that they're not accessible by the user or other apps.



    I have two questions:




    1. Does that placement for the content fit with iOS recommendations/best practices?


    2. Because I have little obj c/iOS experience, I'd be super grateful if you lovely people could cast your eyes over the code and review it?



    // *** blah.h
    #import <React/RCTBridgeModule.h>

    @interface Blah : NSObject <RCTBridgeModule>
    @end


    // *** blah.m
    #import "Blah.h"

    @implementation Blah

    RCT_EXPORT_MODULE();

    RCT_EXPORT_METHOD(createAppDataPath:(NSString *)namespace findEventsWithResolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject){

    NSUInteger length = [namespace length];

    if (length < 1) {
    reject(@"namespace_invalid", @"Namespace param should be non-empty string", nil);
    return;
    }

    // ref: https://stackoverflow.com/a/17430820/1937302

    @try {

    NSString *appSupportDir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject];
    NSString *cacheDir = [appSupportDir stringByAppendingString: [NSString stringWithFormat:@"/%@", namespace]];

    // check for existence of directory:
    BOOL isDir;
    BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:cacheDir isDirectory:&isDir];

    if (!exists) {
    NSError *error = nil;
    // if not present, create it:
    BOOL result = [[NSFileManager defaultManager] createDirectoryAtPath:cacheDir withIntermediateDirectories:YES attributes:nil error:&error];
    if (!result) {
    reject(@"cant_create", @"Can't create directory", error);
    return;
    }
    } else if (!isDir) {
    reject(@"non_directory_path_exists", @"Path already exists as a non-directory", nil);
    return;
    }

    // now mark the directory as excluded from iCloud backups:
    NSURL *url = [NSURL fileURLWithPath:cacheDir];
    NSError *error = nil;
    BOOL result = [url setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:&error];

    if (!result) {
    reject(@"cant_exclude_from_backups", @"Can't exclude from backups", error);
    return;
    }

    resolve(cacheDir);

    }
    @catch(NSException *exception) {
    // TODO: capture information from exception and pass to rejection?
    // ref: https://stackoverflow.com/questions/43561531/how-to-convert-an-exception-into-an-nserror-object
    // ref: https://stackoverflow.com/a/4654759/1937302
    // ref: https://developer.apple.com/documentation/foundation/nsexception
    reject(@"exception", @"An exception has occurred", nil);
    }
    }

    @end









    share|improve this question











    $endgroup$















      2












      2








      2





      $begingroup$


      I'm using react native to build an iOS app, but have little to no experience in obj C or iOS development. The app I'm building has a bunch of content files that aren't user specific, will be downloaded from some CDN, and will (mostly) be behind a paywall. As I understand it, the best place for this would be somewhere within Application Support (the Cache dir doesn't seem to fit the bill because this is more about allowing users to download content for offline use than caching per se. Also, I think there's no guarantees about the lifetime of files in the Cache dir(?).). Also, I want to make sure that those content files aren't backed up to iCloud or anywhere else; and that they're not accessible by the user or other apps.



      I have two questions:




      1. Does that placement for the content fit with iOS recommendations/best practices?


      2. Because I have little obj c/iOS experience, I'd be super grateful if you lovely people could cast your eyes over the code and review it?



      // *** blah.h
      #import <React/RCTBridgeModule.h>

      @interface Blah : NSObject <RCTBridgeModule>
      @end


      // *** blah.m
      #import "Blah.h"

      @implementation Blah

      RCT_EXPORT_MODULE();

      RCT_EXPORT_METHOD(createAppDataPath:(NSString *)namespace findEventsWithResolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject){

      NSUInteger length = [namespace length];

      if (length < 1) {
      reject(@"namespace_invalid", @"Namespace param should be non-empty string", nil);
      return;
      }

      // ref: https://stackoverflow.com/a/17430820/1937302

      @try {

      NSString *appSupportDir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject];
      NSString *cacheDir = [appSupportDir stringByAppendingString: [NSString stringWithFormat:@"/%@", namespace]];

      // check for existence of directory:
      BOOL isDir;
      BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:cacheDir isDirectory:&isDir];

      if (!exists) {
      NSError *error = nil;
      // if not present, create it:
      BOOL result = [[NSFileManager defaultManager] createDirectoryAtPath:cacheDir withIntermediateDirectories:YES attributes:nil error:&error];
      if (!result) {
      reject(@"cant_create", @"Can't create directory", error);
      return;
      }
      } else if (!isDir) {
      reject(@"non_directory_path_exists", @"Path already exists as a non-directory", nil);
      return;
      }

      // now mark the directory as excluded from iCloud backups:
      NSURL *url = [NSURL fileURLWithPath:cacheDir];
      NSError *error = nil;
      BOOL result = [url setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:&error];

      if (!result) {
      reject(@"cant_exclude_from_backups", @"Can't exclude from backups", error);
      return;
      }

      resolve(cacheDir);

      }
      @catch(NSException *exception) {
      // TODO: capture information from exception and pass to rejection?
      // ref: https://stackoverflow.com/questions/43561531/how-to-convert-an-exception-into-an-nserror-object
      // ref: https://stackoverflow.com/a/4654759/1937302
      // ref: https://developer.apple.com/documentation/foundation/nsexception
      reject(@"exception", @"An exception has occurred", nil);
      }
      }

      @end









      share|improve this question











      $endgroup$




      I'm using react native to build an iOS app, but have little to no experience in obj C or iOS development. The app I'm building has a bunch of content files that aren't user specific, will be downloaded from some CDN, and will (mostly) be behind a paywall. As I understand it, the best place for this would be somewhere within Application Support (the Cache dir doesn't seem to fit the bill because this is more about allowing users to download content for offline use than caching per se. Also, I think there's no guarantees about the lifetime of files in the Cache dir(?).). Also, I want to make sure that those content files aren't backed up to iCloud or anywhere else; and that they're not accessible by the user or other apps.



      I have two questions:




      1. Does that placement for the content fit with iOS recommendations/best practices?


      2. Because I have little obj c/iOS experience, I'd be super grateful if you lovely people could cast your eyes over the code and review it?



      // *** blah.h
      #import <React/RCTBridgeModule.h>

      @interface Blah : NSObject <RCTBridgeModule>
      @end


      // *** blah.m
      #import "Blah.h"

      @implementation Blah

      RCT_EXPORT_MODULE();

      RCT_EXPORT_METHOD(createAppDataPath:(NSString *)namespace findEventsWithResolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject){

      NSUInteger length = [namespace length];

      if (length < 1) {
      reject(@"namespace_invalid", @"Namespace param should be non-empty string", nil);
      return;
      }

      // ref: https://stackoverflow.com/a/17430820/1937302

      @try {

      NSString *appSupportDir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject];
      NSString *cacheDir = [appSupportDir stringByAppendingString: [NSString stringWithFormat:@"/%@", namespace]];

      // check for existence of directory:
      BOOL isDir;
      BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:cacheDir isDirectory:&isDir];

      if (!exists) {
      NSError *error = nil;
      // if not present, create it:
      BOOL result = [[NSFileManager defaultManager] createDirectoryAtPath:cacheDir withIntermediateDirectories:YES attributes:nil error:&error];
      if (!result) {
      reject(@"cant_create", @"Can't create directory", error);
      return;
      }
      } else if (!isDir) {
      reject(@"non_directory_path_exists", @"Path already exists as a non-directory", nil);
      return;
      }

      // now mark the directory as excluded from iCloud backups:
      NSURL *url = [NSURL fileURLWithPath:cacheDir];
      NSError *error = nil;
      BOOL result = [url setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:&error];

      if (!result) {
      reject(@"cant_exclude_from_backups", @"Can't exclude from backups", error);
      return;
      }

      resolve(cacheDir);

      }
      @catch(NSException *exception) {
      // TODO: capture information from exception and pass to rejection?
      // ref: https://stackoverflow.com/questions/43561531/how-to-convert-an-exception-into-an-nserror-object
      // ref: https://stackoverflow.com/a/4654759/1937302
      // ref: https://developer.apple.com/documentation/foundation/nsexception
      reject(@"exception", @"An exception has occurred", nil);
      }
      }

      @end






      objective-c ios react-native






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 23 '18 at 15:37







      Ben

















      asked Dec 23 '18 at 12:48









      BenBen

      112




      112






















          1 Answer
          1






          active

          oldest

          votes


















          0












          $begingroup$

          File System Basics tells us:




          The contents of the Library directory (with the exception of the Caches subdirectory) are backed up by iTunes and iCloud.




          And




          Put data cache files in the Library/Caches/ directory. Cache data can be used for any data that needs to persist longer than temporary data, but not as long as a support file. Generally speaking, the application does not require cache data to operate properly, but it can use cache data to improve performance. Examples of cache data include (but are not limited to) database cache files and transient, downloadable content. Note that the system may delete the Caches/ directory to free up disk space, so your app must be able to re-create or download these files as needed.




          If this content is readily re-downloadable, Caches might actually be a reasonable idea. It makes your app a “good citizen”. If the user is running low on storage, it might be better to allow re-downloadable content to be removed rather than tempting the user, looking at their storage taken up by various apps, to contemplate removing your app because it’s taking up a lot of unreclaimable space.



          If you want to ensure the content will never be deleted when the device runs low on space, then go ahead and put it in the Application Support directory, but manually exclude it from backups, like you have done.



          Feel free to refer the iOS Storage Best Practices video (and that page has useful links).





          You said:




          I think there's no guarantees about the lifetime of files in the Cache dir




          Correct. In practice, when (a) the device runs low on space; and (b) your app is not running, the OS can purge this directory. It starts with apps that have been use less recently.




          Also, I want to make sure that those content files aren't backed up to iCloud or anywhere else; and that they're not accessible by the user or other apps.




          By the way, whether it’s backed-up or not and whether it’s accessible by the user are two different questions. E.g., files in the Application Support directory are backed-up (other than, obviously, content of the Caches folder or those files explicitly designated to not be backed-up). But the contents are not visible to the user. Only user documents stored in Documents folder or iCloud Drive are visible to the end-user.



          So, if your content is not readily re-downloadable, but you don’t want to expose them to the individual files, Application Support (without specifying NSURLIsExcludedFromBackupKey) might be prudent. It’s your call.






          share|improve this answer









          $endgroup$













            Your Answer





            StackExchange.ifUsing("editor", function () {
            return StackExchange.using("mathjaxEditing", function () {
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            });
            });
            }, "mathjax-editing");

            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "196"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210220%2fcreating-directory-within-application-support-and-preventing-icloud-backup%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0












            $begingroup$

            File System Basics tells us:




            The contents of the Library directory (with the exception of the Caches subdirectory) are backed up by iTunes and iCloud.




            And




            Put data cache files in the Library/Caches/ directory. Cache data can be used for any data that needs to persist longer than temporary data, but not as long as a support file. Generally speaking, the application does not require cache data to operate properly, but it can use cache data to improve performance. Examples of cache data include (but are not limited to) database cache files and transient, downloadable content. Note that the system may delete the Caches/ directory to free up disk space, so your app must be able to re-create or download these files as needed.




            If this content is readily re-downloadable, Caches might actually be a reasonable idea. It makes your app a “good citizen”. If the user is running low on storage, it might be better to allow re-downloadable content to be removed rather than tempting the user, looking at their storage taken up by various apps, to contemplate removing your app because it’s taking up a lot of unreclaimable space.



            If you want to ensure the content will never be deleted when the device runs low on space, then go ahead and put it in the Application Support directory, but manually exclude it from backups, like you have done.



            Feel free to refer the iOS Storage Best Practices video (and that page has useful links).





            You said:




            I think there's no guarantees about the lifetime of files in the Cache dir




            Correct. In practice, when (a) the device runs low on space; and (b) your app is not running, the OS can purge this directory. It starts with apps that have been use less recently.




            Also, I want to make sure that those content files aren't backed up to iCloud or anywhere else; and that they're not accessible by the user or other apps.




            By the way, whether it’s backed-up or not and whether it’s accessible by the user are two different questions. E.g., files in the Application Support directory are backed-up (other than, obviously, content of the Caches folder or those files explicitly designated to not be backed-up). But the contents are not visible to the user. Only user documents stored in Documents folder or iCloud Drive are visible to the end-user.



            So, if your content is not readily re-downloadable, but you don’t want to expose them to the individual files, Application Support (without specifying NSURLIsExcludedFromBackupKey) might be prudent. It’s your call.






            share|improve this answer









            $endgroup$


















              0












              $begingroup$

              File System Basics tells us:




              The contents of the Library directory (with the exception of the Caches subdirectory) are backed up by iTunes and iCloud.




              And




              Put data cache files in the Library/Caches/ directory. Cache data can be used for any data that needs to persist longer than temporary data, but not as long as a support file. Generally speaking, the application does not require cache data to operate properly, but it can use cache data to improve performance. Examples of cache data include (but are not limited to) database cache files and transient, downloadable content. Note that the system may delete the Caches/ directory to free up disk space, so your app must be able to re-create or download these files as needed.




              If this content is readily re-downloadable, Caches might actually be a reasonable idea. It makes your app a “good citizen”. If the user is running low on storage, it might be better to allow re-downloadable content to be removed rather than tempting the user, looking at their storage taken up by various apps, to contemplate removing your app because it’s taking up a lot of unreclaimable space.



              If you want to ensure the content will never be deleted when the device runs low on space, then go ahead and put it in the Application Support directory, but manually exclude it from backups, like you have done.



              Feel free to refer the iOS Storage Best Practices video (and that page has useful links).





              You said:




              I think there's no guarantees about the lifetime of files in the Cache dir




              Correct. In practice, when (a) the device runs low on space; and (b) your app is not running, the OS can purge this directory. It starts with apps that have been use less recently.




              Also, I want to make sure that those content files aren't backed up to iCloud or anywhere else; and that they're not accessible by the user or other apps.




              By the way, whether it’s backed-up or not and whether it’s accessible by the user are two different questions. E.g., files in the Application Support directory are backed-up (other than, obviously, content of the Caches folder or those files explicitly designated to not be backed-up). But the contents are not visible to the user. Only user documents stored in Documents folder or iCloud Drive are visible to the end-user.



              So, if your content is not readily re-downloadable, but you don’t want to expose them to the individual files, Application Support (without specifying NSURLIsExcludedFromBackupKey) might be prudent. It’s your call.






              share|improve this answer









              $endgroup$
















                0












                0








                0





                $begingroup$

                File System Basics tells us:




                The contents of the Library directory (with the exception of the Caches subdirectory) are backed up by iTunes and iCloud.




                And




                Put data cache files in the Library/Caches/ directory. Cache data can be used for any data that needs to persist longer than temporary data, but not as long as a support file. Generally speaking, the application does not require cache data to operate properly, but it can use cache data to improve performance. Examples of cache data include (but are not limited to) database cache files and transient, downloadable content. Note that the system may delete the Caches/ directory to free up disk space, so your app must be able to re-create or download these files as needed.




                If this content is readily re-downloadable, Caches might actually be a reasonable idea. It makes your app a “good citizen”. If the user is running low on storage, it might be better to allow re-downloadable content to be removed rather than tempting the user, looking at their storage taken up by various apps, to contemplate removing your app because it’s taking up a lot of unreclaimable space.



                If you want to ensure the content will never be deleted when the device runs low on space, then go ahead and put it in the Application Support directory, but manually exclude it from backups, like you have done.



                Feel free to refer the iOS Storage Best Practices video (and that page has useful links).





                You said:




                I think there's no guarantees about the lifetime of files in the Cache dir




                Correct. In practice, when (a) the device runs low on space; and (b) your app is not running, the OS can purge this directory. It starts with apps that have been use less recently.




                Also, I want to make sure that those content files aren't backed up to iCloud or anywhere else; and that they're not accessible by the user or other apps.




                By the way, whether it’s backed-up or not and whether it’s accessible by the user are two different questions. E.g., files in the Application Support directory are backed-up (other than, obviously, content of the Caches folder or those files explicitly designated to not be backed-up). But the contents are not visible to the user. Only user documents stored in Documents folder or iCloud Drive are visible to the end-user.



                So, if your content is not readily re-downloadable, but you don’t want to expose them to the individual files, Application Support (without specifying NSURLIsExcludedFromBackupKey) might be prudent. It’s your call.






                share|improve this answer









                $endgroup$



                File System Basics tells us:




                The contents of the Library directory (with the exception of the Caches subdirectory) are backed up by iTunes and iCloud.




                And




                Put data cache files in the Library/Caches/ directory. Cache data can be used for any data that needs to persist longer than temporary data, but not as long as a support file. Generally speaking, the application does not require cache data to operate properly, but it can use cache data to improve performance. Examples of cache data include (but are not limited to) database cache files and transient, downloadable content. Note that the system may delete the Caches/ directory to free up disk space, so your app must be able to re-create or download these files as needed.




                If this content is readily re-downloadable, Caches might actually be a reasonable idea. It makes your app a “good citizen”. If the user is running low on storage, it might be better to allow re-downloadable content to be removed rather than tempting the user, looking at their storage taken up by various apps, to contemplate removing your app because it’s taking up a lot of unreclaimable space.



                If you want to ensure the content will never be deleted when the device runs low on space, then go ahead and put it in the Application Support directory, but manually exclude it from backups, like you have done.



                Feel free to refer the iOS Storage Best Practices video (and that page has useful links).





                You said:




                I think there's no guarantees about the lifetime of files in the Cache dir




                Correct. In practice, when (a) the device runs low on space; and (b) your app is not running, the OS can purge this directory. It starts with apps that have been use less recently.




                Also, I want to make sure that those content files aren't backed up to iCloud or anywhere else; and that they're not accessible by the user or other apps.




                By the way, whether it’s backed-up or not and whether it’s accessible by the user are two different questions. E.g., files in the Application Support directory are backed-up (other than, obviously, content of the Caches folder or those files explicitly designated to not be backed-up). But the contents are not visible to the user. Only user documents stored in Documents folder or iCloud Drive are visible to the end-user.



                So, if your content is not readily re-downloadable, but you don’t want to expose them to the individual files, Application Support (without specifying NSURLIsExcludedFromBackupKey) might be prudent. It’s your call.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 10 hours ago









                RobRob

                32639




                32639






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Code Review Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210220%2fcreating-directory-within-application-support-and-preventing-icloud-backup%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

                    How do i solve the “ No module named 'mlxtend' ” issue on Jupyter?

                    Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...