Creating directory within Application Support, and preventing iCloud backup The Next CEO of Stack OverflowCreating 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

Can this note be analyzed as a non-chord tone?

Calculate the Mean mean of two numbers

How to get the last not-null value in an ordered column of a huge table?

Can I calculate next year's exemptions based on this year's refund/amount owed?

Is there an equivalent of cd - for cp or mv

How do I fit a non linear curve?

Pulling the principal components out of a DimensionReducerFunction?

Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?

What is the difference between "hamstring tendon" and "common hamstring tendon"?

Getting Stale Gas Out of a Gas Tank w/out Dropping the Tank

What flight has the highest ratio of timezone difference to flight time?

How to use ReplaceAll on an expression that contains a rule

Sulfuric acid symmetry point group

My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?

Which one is the true statement?

Do I need to write [sic] when including a quotation with a number less than 10 that isn't written out?

Does destroying a Lich's phylactery destroy the soul within it?

Is it ever safe to open a suspicious HTML file (e.g. email attachment)?

How to Implement Deterministic Encryption Safely in .NET

Is "three point ish" an acceptable use of ish?

Computationally populating tables with probability data

Players Circumventing the limitations of Wish

What day is it again?

Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?



Creating directory within Application Support, and preventing iCloud backup



The Next CEO of Stack OverflowCreating 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$




bumped to the homepage by Community 4 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.



















    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$




    bumped to the homepage by Community 4 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

















      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





      bumped to the homepage by Community 4 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 4 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















          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 Mar 1 at 21:49









                RobRob

                38339




                38339



























                    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

                    बाताम इन्हें भी देखें सन्दर्भ दिक्चालन सूची1°05′00″N 104°02′0″E / 1.08333°N 104.03333°E / 1.08333; 104.033331°05′00″N 104°02′0″E / 1.08333°N 104.03333°E / 1.08333; 104.03333

                    Why is the 'in' operator throwing an error with a string literal instead of logging false?Why can't I use switch statement on a String?Python join: why is it string.join(list) instead of list.join(string)?Multiline String Literal in C#Why does comparing strings using either '==' or 'is' sometimes produce a different result?How to initialize an array's length in javascript?How can I print literal curly-brace characters in python string and also use .format on it?Why does ++[[]][+[]]+[+[]] return the string “10”?Why is char[] preferred over String for passwords?Why does this code using random strings print “hello world”?jQuery.inArray(), how to use it right?

                    How can we generalize the fact of finite dimensional vector space to an infinte dimensional case?$k[x]$-module and cyclic module over a finite dimensional vector spaceSubspace of a finite dimensional space is finite dimensionalIf V is an infinite-dimensional vector space, and S is an infinite-dimensional subspace of V, must the dimension of V/S be finite? ExplainWhy is an infinite dimensional space so different than a finite dimensional one?base for finite dimensional vector space is not infinite dimensional vector space?Any finite-dimensional vector space is the dual space of anotherHaving Trouble Understanding Meaning Of A Finite-Dimensional Vector SpaceProve that “Every subspaces of a finite-dimensional vector space is finite-dimensional”Ring as a finite dimensional Vector space over a field KQuestion regarding basis and dimension