Search code examples
iosnsfilemanager

iOS - Flag entire Document directory as do not backup


My application got rejected by Apple due to :

2.23: Apps must follow the iOS Data Storage Guidelines or they will be rejected

so is it possible that flag entire Document directory as do no backup ? my application runs in iOS 6.1 and higher .

I am familiar with this code , but I don't know hot to mark my Document directory with it

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

    NSError *error = nil;
    BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
                                  forKey: NSURLIsExcludedFromBackupKey error: &error];
    if(!success){
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }
    return success;
}

EDITED :

Apple has told me that iCloud backups my photos from image gallery , I load images of gallery like this :

- (void)setupPageScroll {

    NSString *imgCount;
    int i;

    [_scrollView setContentSize:CGSizeMake(_scrollView.frame.size.width * _pageControl.numberOfPages, _scrollView.frame.size.height)];
    _scrollView.delegate = self;

    for (i = 0 ; i < 10 ; i++) {

          imgCount  = [NSString stringWithFormat:@"%@%d.jpg",_gallName , i];
         [self createPageWithImage:[UIImage imageNamed:imgCount] forPage:i];
    }

}




- (void)createPageWithImage:(UIImage *)images forPage:(int)page
{
    UIView *newView = [[UIView alloc] initWithFrame: CGRectMake(_scrollView.frame.size.width * page, 0, _scrollView.frame.size.width, _scrollView.frame.size.height)];


    UIImageView *tempImage = [[UIImageView alloc]initWithImage:images];
    [tempImage setContentMode:UIViewContentModeScaleAspectFit];
    tempImage.frame = _galleryView.frame;
    _imgGallery = tempImage;
    [newView addSubview: _imgGallery];

    [_scrollView addSubview: newView];

}



- (IBAction)pageChanged:(id)sender {

    CGRect pageRect = CGRectMake(_pageControl.currentPage * _scrollView.frame.size.width, 0, _scrollView.frame.size.width, _scrollView.frame.size.height);
    [_scrollView scrollRectToVisible: pageRect animated: YES];

}

How can skip these images ?


Solution

  • ... And finally my application has been approved . just follow this instruction :

    put this code on appDelegate.m (didFinishLunching)

    NSString *docsDir;
    NSArray *dirPaths;
    NSURL * finalURL;
    dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    docsDir = [dirPaths objectAtIndex:0];
    
    
    finalURL = [NSURL fileURLWithPath:docsDir];
    
    
    [self addSkipBackupAttributeToItemAtURL:finalURL];
    

    and skip backup :

    - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
    
    {
    
        assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);
    
    
    
        NSError *error = nil;
    
        BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
    
                                      forKey: NSURLIsExcludedFromBackupKey error: &error];
    
        if(!success){
    
            NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    
        }
    
        return success;
    }