码迷,mamicode.com
首页 > 移动开发 > 详细

ios应用, 设置不自动备份到iCloud

时间:2014-08-07 19:15:20      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   os   io   文件   for   ar   

原创文章,转载请注明出处

ios项目,如果有内置下载或者程序动态生成文件的话,就要注意所下载或生成的文件,要不要自动备份到iCloud

如果没有合适的理由就自动上传大文件的话,可能在不能通过应用审核. 收到一下类似这样的答复

We also found that your app does not follow the iOS Data Storage Guidelines, which is required per the App Store Review Guidelines.

例如有人遇到同样问题 http://stackoverflow.com/questions/16239147/ios-do-not-back-up-attribute

苹果给出的设置方法:官方文档 https://developer.apple.com/Library/ios/qa/qa1719/_index.html

应用到项目中, 具体代码如下

#define DownLoad_Directory "Download_Dir"

#pragma mark Download_Dir
void DeviceClass::initDownloadDir(){
    string l_strDocumentDir = cocos2d::CCFileUtils::sharedFileUtils()->getWritablePath();
    l_strDocumentDir.append(DownLoad_Directory);
    
    NSString* l_strDownloadDir = [NSString stringWithUTF8String:l_strDocumentDir.c_str()];
    NSError* l_error;
    if (![[NSFileManager defaultManager] fileExistsAtPath:l_strDownloadDir]){
        [[NSFileManager defaultManager] createDirectoryAtPath:l_strDownloadDir withIntermediateDirectories:NO attributes:nil error:&l_error]; //Create folder
        
        // exclude downloads from iCloud backup
        NSURL *url = [NSURL fileURLWithPath:l_strDownloadDir];
        if(strcmp(g_systemVersion.c_str(), "5.1") >=0 ){
            if ([url setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&l_error] == NO) {
                NSLog(@"Error: Unable to exclude l_strDownloadDir from backup: %@", l_error);
            }
        }
    }
    
    //this->setDonotBackupInICloud();
}
就是在可写目录下建立一个新文件夹, 存放下载文件(需要的话,自动生成的文件也放到这), 并标记这个目录不会被上传到iCloud

感谢梅俊同事的提醒


测试方法:

设置->iCloud->管理储存空间->备份(如果有多设备的话,选择设备)

应用多的话,点击"显示所有应用" 查到你的应用,在iCloud上备份内容的总容量.

打开和关闭这个接口, 会发现, 你的应用在iCloud上的备份mwjg容量是不是一样.

ios应用, 设置不自动备份到iCloud,布布扣,bubuko.com

ios应用, 设置不自动备份到iCloud

标签:style   http   color   os   io   文件   for   ar   

原文地址:http://blog.csdn.net/rct1985/article/details/38420087

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!