15

我的申请被苹果拒绝了,原因是:

2.23:应用程序必须遵循 iOS 数据存储指南,否则将被拒绝

那么是否有可能将整个 Document 目录标记为没有备份?我的应用程序在 iOS 6.1 和更高版本中运行。

我熟悉这段代码,但我不知道用它来标记我的文档目录

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

编辑:

Apple 告诉我 iCloud 会从图片库备份我的照片,我会像这样加载图库的图片:

- (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];

}

怎么能跳过这些图像?

4

2 回答 2

23

... 最后我的申请被批准了。只需按照以下说明进行操作:

将此代码放在 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];

并跳过备份:

- (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;
}
于 2013-11-23T09:49:48.440 回答
9

您可以仅将父文件夹标记为无备份,而不是每个文件。但它不应该是 Documents 目录,因为它应该只包含用户创建的内容。您应该使用库/应用程序支持技术问答 QA1719

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *directory = [paths objectAtIndex:0];
directory = [directory stringByAppendingPathComponent:@"MyData"];

NSFileManager *fileManager = [NSFileManager defaultManager];

if ([fileManager fileExistsAtPath:directory] == NO) {

    NSError *error;
    if ([fileManager createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:&error] == NO) {
        NSLog(@"Error: Unable to create directory: %@", error);
    }

    NSURL *url = [NSURL fileURLWithPath:directory];
    // exclude downloads from iCloud backup
    if ([url setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error] == NO) {
        NSLog(@"Error: Unable to exclude directory from backup: %@", error);
    }
}

致谢:新视博客

于 2013-11-14T09:08:01.800 回答