iOS - Flag entire Document directory as do not backup

前端 未结 2 1019
独厮守ぢ
独厮守ぢ 2020-12-29 09:04

My application got rejected by Apple due to :

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

so

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 09:39

    ... 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;
    }
    

提交回复
热议问题