ios系统设置不主动备份到icloud

本文探讨了在iOS项目中如何正确处理文件的iCloud备份,避免应用审核受阻。介绍了一个实例,演示如何创建一个不会被iCloud备份的文件夹,用于存储下载或自动生成的文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

苹果给出的设置方法: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容量是不是一样.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值